A C++11 header-only library that implements HTTP/HTTPS servers and clients. Include one header file and link optional TLS backends when you need encryption.
Overview
cpp-httplib gives C++ programs a compact way to speak HTTP/1.1 over plain TCP or TLS. Setup is meant to stay simple: add the header to a project and start defining routes or client requests without pulling in a large framework.
The library covers both sides of the connection. Servers can register handlers for common and custom verbs, serve static files, stream bodies, and optionally expose WebSockets and server-sent events. Clients support ordinary requests, downloads, and TLS with several backend choices including OpenSSL, Mbed TLS, and wolfSSL, plus hooks for custom certificate verification and mutual TLS.
APIs use lambdas and straightforward method names. Networking is blocking with a thread pool rather than non-blocking I/O, and only HTTP/1.1 is supported. The authors position it for embedded HTTP in tools, small API services, mocks in tests, and similar workloads rather than huge concurrent fan-out.
Optional features include content encodings, file uploads, access and error logging reminiscent of traditional web servers, and platform integration for system certificate stores on macOS and Windows. It targets 64-bit environments on Windows, macOS, and Linux with a C++11-or-later toolchain.
Key features
- HTTP/1.1 server and client
- Single-file header-only distribution
- SSL/TLS via multiple backends
- WebSocket and SSE support
- Static file serving
- Custom HTTP methods and routing
- Stream-oriented request and response APIs
- Platform CA store integration
Use cases
- Lightweight local API servers
- HTTP clients inside C++ tools
- Mock HTTP services for testing
- Embedded HTTP in desktop utilities