qicosmos/cinatra: a header-only C++20 HTTP server where the compiler flags are your job
A cross-platform, header-only, high-performance HTTP library/framework built with modern C++ (C++20).
At a glance
- What is it?
- cinatra is a header-only C++20 HTTP library with a coroutine server and client, aspect hooks, a reverse proxy and a rate limiter. It has no package to install, so the build flags, the CPU instruction set and the compiler version are all on you.
- Who is it for?
- Pick cinatra when you already build with a C++20 compiler (gcc 10.2, clang 13 or Visual Studio 2022) and want an HTTP1.1 server, a coroutine client, a reverse proxy and aspects in headers you can drop into CMake. Skip it if you need HTTP/2, a packaged install, or performance figures you can verify from the repository text.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 2 days ago.
- What is it written in?
- Mainly C++, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 25, 2026, and from our analysis. They are not legal advice.
Star history
- qicosmos/cinatra2,190 ★ · +7
| Repository | 2026-10-08 | 2026-11-25 |
|---|---|---|
| qicosmos/cinatra | 2.2k | 2.2k |
7 Stars in the last 48 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
Header-only means you set the CMake flags yourself, and g++ needs two more
cinatra is header-only. There is no library to link and no package command in the text: you add the include directory and set compile options. On Linux the flags are -pthread and -std=c++20, written as:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -std=c++20")If you compile with g++, two more settings are required, -fcoroutines and, for release builds, -fno-tree-slp-vectorize through CMAKE_CXX_FLAGS_RELEASE. The second one is an odd detail to find in a quick-start, and it tells you that a default g++ release build is not what the author expects you to ship.
The stated compiler floor is C++20 with gcc 10.2, clang 13, Visual Studio 2022 or newer. The CI table is narrower: Ubuntu 22.04 with clang 14.0.0 and gcc 11.2.0, macOS Monterey 12 with AppleClang 14.0.0.14000029, and Windows Server 2022 with MSVC 19.33.31630.0. A toolchain older than those has no documented path.
Only one SIMD option may be on, and more than one stops the build
cinatra can use CPU instruction sets to speed up its internal logic, switched on by a macro that CMake sets from ENABLE_SIMD. The README warns you to make sure the CPU supports the chosen set before building with it. The three accepted values are:
cmake -DENABLE_SIMD=SSE42 .. # 启用sse4.2指令集
cmake -DENABLE_SIMD=AVX2 .. # 启用avx2指令集
cmake -DENABLE_SIMD=AARCH64 .. # arm环境下,启用neon指令集The comments say SSE4.2, AVX2, and NEON for ARM respectively. Only one instruction set can be enabled at a time, and enabling several makes compilation fail. The practical consequence is that a binary built with AVX2 on one machine and run on an older CPU is a risk you manage yourself, and the text does not describe a runtime check.
Handlers are coroutine-aware, and a plain lambda is the five-line case
The smallest server creates a coro_http_server with a thread count and a port, registers a handler with set_http_handler for the methods you want, and calls sync_start. The first example uses std::thread::hardware_concurrency() for the thread count and listens on 8080, answering GET and POST on the root path with hello world through res.set_status_and_content.
Coroutine handlers use the same registration call but return async_simple::coro::Lazy<void>, as in the basic usage example with a /coro route. That ties your handler types to the async_simple library, which the example headers pull in. A handler can also be a member function on your own struct, as the person_t example shows with a foo method taking the request and response. The README presents these as examples, and the matching client is also coroutine based, covering get and post, file upload and download, websocket, redirect and proxy.
Aspects are structs with before and after hooks that can short-circuit the request
The aspect example defines a log_t struct and a check struct. Each has a before function and, for the logger, an after function, and both take the request and response objects and return bool. The logger prints before log and after log around your business logic.
The check aspect reads the header named name with req.get_header_value and answers bad request when it is empty. A valid request passes to the next aspect, here the logger, which prints before the business code runs and after it finishes. You can add as many aspects as you like. The consequence is that cross-cutting rules such as authentication stay out of handlers, but a header check like this one rejects every client that does not send the header, so your health checks and browsers need to send it too. The shown source is cut off partway through the check function, so confirm the exact return behavior against the repository.
RESTful parameters come in two forms, and unregistered names produce errors
Path parameters have two styles. The first uses a regular expression, for example R"(/numbers/(\d+)/test/(\d+))", where \d+ restricts each value to digits and you read the captures from req.matches_[1] and req.matches_[2]. A request to /numbers/1234/test/5678 yields 1234 and 5678.
The second style accepts any characters with named segments such as /string/:id/test/:name, and you read them from req.params_. The names must be the registered variables, and the README says that if they are not, the program still runs but reports an error. In the example, requesting /string/params_1/test/api_test makes the browser return the string api_test.
One inconsistency is worth noting: this example declares handlers as request and response, while the basic examples use coro_http_request and coro_http_response. Check which type names your version exposes before copying.
The reverse proxy needs three steps, and weighted round robin needs weights you supply
The reverse proxy takes a thread count and a port, a list of destination hosts, and a start call with a load balancing algorithm. The round robin example is:
reverse_proxy proxy_rr(10, 8091);
proxy_rr.add_dest_host("127.0.0.1:9001");
proxy_rr.add_dest_host("127.0.0.1:9002");
proxy_rr.add_dest_host("127.0.0.1:9003");
proxy_rr.start_reverse_proxy<GET, POST>("/rr", true,
coro_io::load_blance_algorithm::RR);The spelling load_blance_algorithm is how the identifier appears, so do not correct it. Visiting /rr on port 8091 sends you to one of the three servers. Random uses coro_io::load_blance_algorithm::random, while weight round robin needs a weight per host passed to add_dest_host.
The rate limiter is the other protective piece: you declare rate_limiter objects such as rate_limiter(1.0, 1), and call allow() in a handler. When it returns false, the example answers service_unavailable with a message about excessive access frequency. Limiters work with coroutines and plain functions, and the separate rate limiter guide lists six external interfaces.
HTTP1.1 and 1.0 are the stated scope, and the performance claim has no figures in the text
The README says cinatra supports http1.1 and 1.0, ssl and websocket. HTTP/2 and HTTP/3 are not listed, so a service that must speak them needs another layer in front. The suggested uses are database access servers, file upload and download servers and real-time push servers, and it says an mqtt server could be built on top.
The README also calls cinatra one of the best performing HTTP servers in the world and points to a performance section, but that section is cut off and no number survives, so treat the claim as unverified here. The repository does include example/benchmark.cpp and a press_tool directory if you want to measure it yourself.
On upkeep, the repository is not archived and the last push was on 2026-11-01. Releases are 1.0.0 on 2026-04-29, 0.9.9 on 2026-04-02 and 0.9.8 on 2026-01-13. It is MIT licensed and the repository carries an iguana entry alongside a .gitmodules file.
Editorial conclusion
Pick cinatra when you already build with a C++20 compiler (gcc 10.2, clang 13 or Visual Studio 2022) and want an HTTP1.1 server, a coroutine client, a reverse proxy and aspects in headers you can drop into CMake. Skip it if you need HTTP/2, a packaged install, or performance figures you can verify from the repository text. Before committing, build the quick example on your exact compiler and confirm which SIMD option your CPU supports.
Frequently asked questions
Is qicosmos/cinatra header-only?
Yes. You add the include directory and set compile options such as -pthread and -std=c++20; g++ also needs -fcoroutines.
Which compilers does cinatra require?
A C++20 compiler: gcc 10.2, clang 13, Visual Studio 2022 or newer. The CI table covers Ubuntu 22.04 with clang 14.0.0 and gcc 11.2.0, macOS Monterey 12 with AppleClang, and Windows Server 2022 with MSVC.
Which protocols does cinatra support?
The README lists http1.1 and 1.0, ssl and websocket. It also provides a coroutine-based http and https client with get, post, file transfer, websocket, redirect and proxy.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/qicosmos-cinatra)Star history chart for your README
[](https://hysenlabs.com/projects/qicosmos-cinatra)Was this useful?