Minimal and lightweight HTTP server library for the Odin programming language.
Inspired by Fiber and designed with simplicity and performance in mind, HTTPO provides a clean, minimal API for building HTTP services in Odin. It handles routing, request parsing, and response generation with zero external dependencies.
- Lightweight: Minimal overhead, focused on core HTTP functionality.
- Simple API: Intuitive server setup and endpoint registration.
- Efficient: Built on Odin's core
netpackage with non-blocking I/O and worker threads. - Request Parsing: Automatic parsing of HTTP method, path, headers, and cookies.
- Response Building: Easy creation and customization of HTTP responses.
- Graceful Shutdown: Supports controlled server termination via atomic flags.
- Tested: Includes a comprehensive test suite.
Getting started with HTTPO is easy. A complete server example with graceful shutdown handling is available in the example file.
The Server struct holds the server's state, including its port, allocator, and registered endpoints.
InitServer :: proc(port: u16, allocator := context.allocator) -> ServerCreates a new Server instance on the specified port with an optional allocator.
Listen(s: ^Server, stop: ^bool = nil) -> net.Network_Error: Starts the server to accept connections indefinitely or until thestopflag becomestrue.ListenOnce(s: ^Server) -> net.Network_Error: Accepts and handles a single connection.
AddEndpoint :: proc(server: ^Server, path: string, handler: RequestHandler)Registers a handler function for a specific URL path.
Request: Contains parsed HTTP request data (method, path, headers, cookies, body).Response: Used to construct the HTTP response (status code, headers, body).
Use CreateResponse(status_code: StatusCode) to initialize a Response.
Compile your application with Odin:
odin build .HTTPO includes a test suite. Run it with:
odin test .