$ show CrowCpp/Crow
Crow is a modern C++ microframework for building HTTP and WebSocket services. Designed as a single-header library (or modular headers), it provides a Flask-like routing system with typed URL parameters, a middleware pipeline (global and per-route), built-in JSON parsing and generation, Mustache templating, multipart form handling, static file serving, gzip/deflate compression, and SSL/TLS support. The framework is header-only and leverages C++17/20 features such as std::string_view, std::optional, and constexpr where possible. It includes a comprehensive test suite (Catch2), fuzz testing for security, and extensive documentation via MkDocs and Doxygen. Crow is packaged for multiple platforms (Vcpkg, Homebrew, AUR, Conan, Nixpkgs) and is used in production by several open-source projects. The architecture is event-driven, built on top of Asio (standalone or Boost), with a focus on performance and simplicity. Reusable components include a standalone JSON library, base64 utilities, and a flexible middleware system.
The LLM identified 4 files worth highlighting for reuse:
A standalone JSON parser and writer implemented entirely in headers. Supports reading and writing of JSON objects, arrays, strings, numbers, booleans, and null. Provides type-safe access via `rvalue` (read) and `wvalue` (write) with implicit conversions to standard types. Handles comments and trailing commas. Can be extracted and used in any C++17 project without dependencies beyond the standard library. Demonstrates careful memory management and performance optimization (e.g., manual number formatting with trailing-zero removal).
A collection of reusable utilities including base64 encoding/decoding (`base64encode`, `base64decode`), an insertion-order-preserving map (`ordered_object`), compile-time function traits (`function_traits`), and macros for branch prediction (`CROW_LIKELY`/`CROW_UNLIKELY`). The base64 implementation is efficient and handles both standard and URL-safe alphabets. The `ordered_object` template is a lightweight alternative to std::unordered_map when key order matters, useful for JSON-like structures. All components are self-contained and can be extracted independently.
A thin wrapper around zlib providing gzip and deflate compression/decompression for HTTP content encoding. Provides `compress` and `decompress` functions with configurable compression level. The interface is clean and minimal, hiding zlib's complexity. Can be reused in any C++ project that needs HTTP compression or general gzip handling, given a zlib installation.
Implements a generic middleware pipeline using variadic templates. Middleware classes define `before_handle` and `after_handle` methods that operate on the request/response. The framework automatically resolves middleware dependencies via the `AllContext` type. This pattern is clean, extensible, and can be adapted to other request-response systems. The design demonstrates compile-time ordering and efficient context sharing without virtual dispatch.