Bolt is a minimalist HTTP server/microframework written in pure C, developed as a toy project to explore server-side programming concepts. It was designed to be used by simply including the header files on your project and adding the .c files to your compilation script.
- Minimalistic Design: Designed to be lightweight and simple.
- HTTP Server: Handles incoming HTTP requests.
- Microframework: Provides basic routing and response handling functionalities.
- Path Parameters: Supports extracting path parameters from routes.
- Multi-threaded Processing: Uses pthreads for concurrent request handling.
- Header Manipulation: Capable of setting response headers and accessing request headers.
- HTTP Status Codes: Supports setting HTTP response codes.
- Response Body: Allows setting response body content.
To get started with Bolt, follow these steps:
-
Clone the repository:
git clone https://github.com/your-username/bolt.git cd bolt
-
Include the header files on your project and add bolt's .c files to your compilation script More info about it can be found on the example service's Makefile.
You can define routes using the set_route
function, specifying methods, paths and handlers:
set_route(router, POST, "/hello", hello_handler);
set_route(router, GET, "/user/:name", user_handler);
Create handler functions that conform to the HandlerFunc
function signature:
void count(void *c) {
Context *ctx = get_context(c);
char *response = (char *)malloc(sizeof(char) * 50);
sprintf(response, "{\"count\":%d}", counter++);
set_header(ctx->res->headers, "Content-Type", "application/json");
ctx->res->status_code = 200;
ctx->res->body = response;
}
Register it as a handler setting the path and the method:
void setup_routes(Router *router) {
set_route(router, POST, "/count", count);
}
Bolt uses pthreads to handle multiple requests concurrently. Ensure your system supports pthreads for optimal performance.
Contributions are welcome! Fork the repository and submit a pull request with your changes.
- Inspired by minimalistic HTTP servers and microframeworks.
- Built with love and curiosity.