Skip to content

jonah07/c-web-server

Repository files navigation

c-web-server

How to use

Include httpd.h and define the method handle:

std::string httpd::handle(Request request) {
    return "";
}

The method returns the HTTP response. I recommend to use the class Response to generate it. The parameter request is used to get the URL and more information about the request.

Example code:

std::string httpd::handle(Request request) {
    std::cout << "URL: " << request.getRoute() << "\n";
    std::string html = "<h1>hi</h1>";
    Response response(html);
    return response.generate();
}

This would log the URL and display "hi".

Your main method should look like this, if you want to start the server there:

int main() {
    httpd::start();
}

About

A simple web server written in C++

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors