Skip to content

cpp-httplib

A single-header C++11 library for building HTTP/HTTPS servers and clients.

Stars
17k
Forks
2.8k
Licence
MIT
Language
C++
Last update
6 days ago
Type
Library

What it is

cpp-httplib is a C++ library you add to a project by including one header file, httplib.h. It lets a C++ program act as a web server or as a web client that sends HTTP and HTTPS requests. It uses blocking socket I/O and supports HTTP/1.1 only, and it can use OpenSSL, Mbed TLS, or wolfSSL for encryption.

  • Run a small HTTP server in a C++ program that responds to GET requests
  • Make HTTP or HTTPS requests from a C++ program to an external API
  • Set up mutual TLS so a server verifies client certificates
  • Stream responses or use Server-Sent Events and WebSocket endpoints

Great for

  • C++ developers who need a simple embedded HTTP server or client without a large framework
  • Projects that want to avoid a complex build setup by using a single header file
  • Teams that need HTTPS with a choice of OpenSSL, Mbed TLS, or wolfSSL
  • Developers who want WebSocket, Server-Sent Events, or a stream API from the same library

Not ideal for

  • Apps that need non-blocking, high-concurrency socket I/O, since the README says this is blocking I/O and not the right choice for that
  • Projects that need HTTP/2 or HTTP/3, which the README says are not implemented
  • Targets that are 32-bit, since the README says 32-bit platforms are not supported and security reports for them are closed
Step-by-step guide: how to use cpp-httplibInstall, first run, examples, tips and FAQs

How to get it

  1. 1

    Clone and build from source

    You'll need: A C++11 or later compiler · OpenSSL 3.0 or later, Mbed TLS, or wolfSSL if you need HTTPS

    Clone the repository

    git clone https://github.com/yhirose/cpp-httplib
  2. 2

    Run it

    • Include httplib.h from the cloned repository in your C++ source file
    • Create an httplib::Server object and register a route with Get
    • Call svr.listen("0.0.0.0", 8080) to start serving
    • Open http://localhost:8080/hi in a browser or with curl to check the response
  3. 3

    Get the most out of it

    • Use the SSL/TLS support section to set up HTTPS with httplib::SSLServer and a certificate and key
    • Use set_ca_cert_path and the verification settings to control how a client checks server certificates
    • Set up mutual TLS by passing a client CA to the server and client certificate files to the client
    • Use the SSL error handling methods ssl_error and ssl_backend_error to diagnose failed requests
    • Read the linked stream, Server-Sent Events, and WebSocket guides for those features

Downloads

Strengths

  • Distributed as a single header file, so setup is just an include
  • Supports HTTPS through three TLS backends: OpenSSL, Mbed TLS, and wolfSSL
  • Documentation covers TLS error handling, custom certificate verification, and mutual TLS

Trade-offs

  • Blocking socket I/O and HTTP/1.1 only, which rules out some workloads
  • The README warns that 32-bit platforms are unsupported and not security reviewed
  • Some TLS behavior differs by backend, such as wolfSSL's certificate enumeration limits, so the docs must be read per backend

How it compares

ProjectStarsTypeLevelUpdatedBest for
cpp-httplib (this)17kLibrarybeginner6 days agoC++ developers who need a simple embedded HTTP server or client without a large framework
got15kLibrarybeginner7 days agoNode.js developers who call web APIs from server-side code
entt13.2kLibraryadvanced4 days agoC++ game developers who want an ECS
modern-cpp-tutorial25.9kLearning resourceintermediate29 days agoExperienced C++ developers who want a quick overview of modern features
json50.8kLibrarybeginner4 days agoC++ developers who need to read or write JSON in an application
axum27.7kLibraryintermediate4 days agoRust developers building HTTP APIs or web services

Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.