HTTP API β
This page documents the core HTTP primitives in Vix.
It covers:
- App
- Routing methods
- Request
- Response
All examples are minimal and placed entirely inside main().
App β
Header:
cpp
#include <vix.hpp>Core type:
cpp
vix::AppConstructor β
cpp
App app;Run β
cpp
app.run(8080);Starts the HTTP server on the given port (blocking call).
Routing Methods β
GET β
cpp
app.get(path, handler);POST β
cpp
app.post(path, handler);PUT β
cpp
app.put(path, handler);DELETE β
cpp
app.del(path, handler);Minimal Example β
cpp
#include <vix.hpp>
using namespace vix;
int main()
{
App app;
app.get("/", [](Request&, Response& res) {
res.send("Hello");
});
app.run(8080);
}Request β
Type:
cpp
vix::RequestProvides access to:
- Path parameters
- Query parameters
- Headers
- Body
- JSON payload
Path parameter β
cpp
req.param("id", "0");Returns string value or fallback.
Query parameter β
cpp
req.query_value("page", "1");Headers β
cpp
req.header("User-Agent");
req.has_header("Authorization");Body β
cpp
std::string body = req.body();JSON β
cpp
const auto& j = req.json();Returns parsed JSON (high-level JSON layer).
Response β
Type:
cpp
vix::ResponseControls HTTP output.
Status β
cpp
res.status(201);
res.set_status(404);Send text β
cpp
res.send("Hello");Send JSON β
cpp
res.json({"message", "ok"});Auto-send return β
If a route handler returns:
std::stringβ text response- JSON object β JSON response
Example:
cpp
app.get("/auto", [](Request&, Response&) {
return vix::json::o("message", "auto");
});Behavior Notes β
- If
res.send()orres.json()is called, returned values are ignored. - If nothing is sent, the handler must return a value.
- Status defaults to 200 unless changed.
- Handlers execute synchronously per request context.
Design Philosophy β
The HTTP layer is:
- Minimal
- Explicit
- Deterministic
- Zero hidden middleware stack by default
You control exactly what happens in each handler.