Cerver is a lightweight and straightforward HTTP server library written in C, designed to be easy to use and integrate into your projects. Created by Farhan Ali (@farhaanaliii), this library allows you to quickly set up a server, define routes, and serve static files with minimal setup. Whether you're building a small personal project or a larger application, Cerver provides the essential tools needed to handle HTTP requests efficiently.
- Simple and easy to use
- Supports adding multiple routes
- Serves static files
- Logs HTTP requests
To use cerver, clone the repository and include the server.h and server.c files in your project.
git clone https://github.com/farhaanaliii/cerver.git#include "server.h"
#include <stdio.h>
int main() {
Server server;
init_server(&server, 3000);
add_route("/", "web/index.html");
add_route("/about", "web/about.html");
add_route("/contact", "web/contact.html");
start_server(&server);
return 0;
}typedef struct {
int port;
int server_fd;
int addrlen;
struct sockaddr_in address;
} Server;typedef struct {
char *route;
char *file_path;
} Route;Initializes the server with the specified port.
server: A pointer to theServerstructure.port: The port number to listen on.
Adds a new route to the server.
route: The URL path for the route.file_path: The file path to serve when the route is accessed.
Starts the server and listens for incoming connections.
server: A pointer to theServerstructure.
Feel free to submit issues and pull requests! Contributions are welcome.
This project is licensed under the MIT License - see the LICENSE file for details.