Skip to content

gmorer/http_server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HTTP_PARSER

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.

Example:

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

compil

compile with: make && gcc test/main.c -Iinc/ libserver.a -lpthread inc/http_server.h

roadmap

  • simple request
  • request parsing (thx to http_parser)
  • regex endpoint routing
  • io_uring
  • bufferize read
  • seperate server and http
  • response header
  • middleware
  • https

About

expressJS like library but for C

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published