explaingit

yhirose/cpp-httplib

16,474C++Audience · developerComplexity · 2/5Setup · easy

TLDR

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.

Mindmap

mindmap
  root((cpp-httplib))
    What it does
      HTTP and HTTPS server
      HTTP and HTTPS client
      Single header file
    Server features
      URL routing
      WebSocket support
      Server-Sent Events
      Streaming API
    TLS backends
      OpenSSL
      MbedTLS
      wolfSSL
    Limitations
      HTTP/1.1 only
      Blocking I/O
    Tech Stack
      C++11
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Embed a small HTTP API endpoint inside a desktop or embedded C++ application without pulling in a heavier framework.

USE CASE 2

Add HTTPS client calls to an existing C++ codebase by including a single header file.

USE CASE 3

Expose a WebSocket or Server-Sent Events endpoint from a C++ service with minimal setup.

Tech stack

C++C++11OpenSSLMbedTLSwolfSSL

Getting it running

Difficulty · easy Time to first run · 5min

HTTPS requires linking OpenSSL, MbedTLS, or wolfSSL, pure HTTP works with zero extra dependencies.

In plain English

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.

Copy-paste prompts

Prompt 1
Write a minimal C++ HTTPS server using cpp-httplib that responds to GET /hello with a JSON body, using OpenSSL for TLS.
Prompt 2
Show me how to make a POST request with cpp-httplib's Client, send a JSON body, and check the response status code.
Prompt 3
How do I enable HTTPS in cpp-httplib using a self-signed certificate on Linux, and what preprocessor flag do I need to set?
Prompt 4
Add a WebSocket handler to a cpp-httplib server that echoes back any text message the client sends.
Open on GitHub → Explain another repo

← yhirose on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.