jeremycw/httpserver.h logo

jeremycw/httpserver.h

Free

Single header library for writing non-blocking HTTP servers in C

FreeFree tier
Type
Open Source

About jeremycw/httpserver.h

httpserver.h is a single-header C library for building event-driven, non-blocking HTTP servers. It supports Linux via epoll and BSD/macOS via kqueue, providing a lightweight and high-performance solution for embedded or custom server needs. The library is designed to be easy to integrate — simply include the header and define HTTPSERVER_IMPL before use. Benchmarks show it can handle over 123,000 requests per second with keep-alive connections. The API is documented within the header file itself, and the repository includes examples and a CMake-based build system.

Key Features

Single header file – no separate compilation or dependencies
Event-driven, non-blocking I/O architecture
Supports Linux (epoll) and BSD/macOS (kqueue)
Minimal and easy to integrate into any C project
Well-documented API inside the header
Benchmarked performance over 123,000 requests per second (keep-alive)

Pros & Cons

Pros
  • Extremely lightweight and dependency-free
  • High performance, as shown by benchmarks against Nginx
  • Easy to get started with a single header file
  • Cross-platform support for Linux and BSD/macOS
  • Event-driven model is suitable for concurrent connections without threading
Cons
  • Limited to C language; no built-in support for HTTPS/TLS
  • Not a full-featured web server (e.g., no routing, middleware, or file serving)
  • No Windows support (relies on epoll/kqueue)
  • Documentation mainly in header comments; no separate user guide

Best For

Building lightweight HTTP servers for embedded systemsServing simple REST APIs in C projectsCreating custom web servers for performance-critical applicationsReplacing heavier HTTP libraries in minimal environmentsEducational purposes (learning non-blocking I/O in C)

FAQ

What platforms does httpserver.h support?
Linux (with epoll) and BSD/macOS (with kqueue). There is no Windows support.
How do I use httpserver.h in my project?
Copy the httpserver.h file into your project, include it once with `#define HTTPSERVER_IMPL` before the include, and then use the provided API functions such as `http_server_init()` and `http_server_listen()`.
Is httpserver.h production-ready?
The library demonstrates high performance in benchmarks. However, the author notes that it is not a competitor or replacement for NGINX, and it lacks HTTPS support. Use should be evaluated based on project requirements.
Does httpserver.h support HTTPS?
No, the library currently does not include TLS/SSL support. You would need to wrap it or use a proxy for secure connections.