ExpressJs like http server in C, library with only two functions: init_server()
and start_server()
.
You need to use regex for the path matching.
int main(int argc, char **argv)
{
t_endpoint endpoints[] = {
(t_endpoint){"^/$", 0, &hello_world, 0},
(t_endpoint){"^/sum/(.*)/(.*)$", 2, &sum_ep, 0},
(t_endpoint){"/", 0, &error_404, 0},
ENDPOINTS_END
};
if (!init_server(argc > 1 ? atoi(argv[1]) : 0, endpoints))
{
dprintf(2, "Cannot initialize the server\n");
return (1);
}
launch_server();
return (0);
$ curl localhost:8080/
Hello world
$ curl localhost:8080/sum/42/43
85
$ curl localhost:8080/test
Error 404
see test/main.c
compile with: make && gcc test/main.c -Iinc/ libserver.a -lpthread inc/http_server.h
- simple request
- request parsing (thx to http_parser)
- regex endpoint routing
- io_uring
- bufferize read
- seperate server and http
- response header
- middleware
- https