Wave is a simple C HTTP server library. You can use it to create your backend in C. It supports serving static files.
- First you need to compile the library and add the
libwave.sofile in your codebase. - After that copy the
wave.hheader file of the library in your codebase.
Now the wave library is ready to be used!
Here is an example implementation using the wave library:
#include "wave.h"
void about_handler(int client_fd, const char *request)
{
send_response(client_fd, "This is a custom endpoint!", 200);
}
void custom_handler(int client_fd, const char *request)
{
send_file_response(client_fd, "index.html");
}
int main(void)
{
server_t *server = init_server(8080);
add_route(server, "GET", "/", default_handler);
add_route(server, "GET", "/about", about_handler);
add_route(server, "GET", "/custom", custom_handler);
start_server(server);
return 0;
}You can compile your webserver with:
gcc main.c -I. -lwave -L. -Wl,-rpath,.🎉 And your webserver now ready to go !
