Architecture
cppnet's layered design — parsing, routing, business logic, and the socket layer — and the core types in each.
cppnet follows a layered architecture. Each layer has a single
responsibility, and requests flow through them in order.
The layers
| Layer | Responsibility | Status |
|---|---|---|
| Socket | Manage network connections; read/write raw bytes. | Not yet implemented — bring your own (e.g. Asio). |
| Parsing | Turn raw HTTP bytes into a typed Request. | Implemented (llhttp). |
| Routing | Map a request's method + path to a handler. | Implemented. |
| Business logic | Your per-endpoint handlers. | You implement these. |
Core types
Request
Encapsulates an incoming HTTP request — method, URL/path, headers, query params, and body — with helpers for accessing header and query-parameter values.
types.h
Defines the enums the rest of the library uses:
Method— HTTP methods (GET,POST, …).Version— HTTP versions.StatusCode— HTTP status codes.
Plus type aliases for headers and query parameters.
Parser
Wraps llhttp to parse requests. It manages parser state and exposes the parsed
Request. As llhttp recognizes tokens it invokes callbacks (on_url,
on_header_field, on_header_value, on_body, on_message_complete) that
populate the Request.
Router
Maps requests to handlers. It builds a RouteKey from a request's method and
path and looks it up in an std::unordered_map for efficient dispatch. Routes
are registered with add_route(method, path, handler).
BaseHandler
The abstract base class for handlers. Each endpoint subclass implements
handle(const Request&) and returns a response string.
Source layout
cppnet/
├── include/http/
│ ├── handlers/ # base_handler.h, json_handler.h
│ ├── parser/ # parser.h, callbacks.h, utils.h
│ ├── request.h
│ ├── router.h
│ └── types.h
├── src/http/
│ ├── request.cpp
│ └── parser/ # parser.cpp, callbacks.cpp, utils.cpp
└── tests/
├── http/parser/ # parser tests (simple, complex, gtests)
└── handler/ # POST/PUT/PATCH/DELETE handler testsNext
See exactly how a request travels through these layers in the Request lifecycle.