gitmyhub

cpp-httplib

C++ ★ 17k updated 2d ago

A C++ header-only HTTP/HTTPS server and client library

cpp-httplib is a single-header C++ library for adding an HTTP or HTTPS server and client to any C++ app, drop one .h file in, include it, and start handling requests or making calls with no linking required.

C++C++11OpenSSLMbedTLSwolfSSLsetup: easycomplexity 2/5

cpp-httplib is a small library that lets a C++ program speak HTTP and HTTPS, either as a web server answering incoming requests or as a client sending requests to other servers. HTTP is the protocol your browser uses to fetch web pages, and HTTPS is the same wrapped in encryption. The unusual thing about this project is that it ships as a single header file: instead of installing a package and linking a compiled library, you drop httplib.h into your project, include it, and start writing handlers right away.

The README shows that defining a server takes a few lines: you create a Server object, register a callback for a URL path, and call listen on a host and port; the callback receives a request and response and fills the response with whatever to send back. The client side is just as compact, with a Client object whose Get method returns the response. The same code path supports HTTPS through an abstraction layer backed by OpenSSL, MbedTLS or wolfSSL, selected via a preprocessor flag. The README also lists support for Server-Sent Events, WebSockets, a streaming API, certificate verification callbacks, peer certificate inspection on the server side, and integration with the system certificate store on macOS and Windows.

Someone would reach for this to embed an HTTP server or client inside a C++ application without dragging in a heavier framework, such as exposing a small API from a desktop tool or adding HTTP calls to an existing program. The README is explicit that the library uses blocking socket I/O, supports only HTTP/1.1, and does not target 32-bit platforms. The repository's primary language is C++11, and the full README is longer than what was provided.

Where it fits