This document shows complete, real-world examples demonstrating how simple, expressive, and powerful Vix is.
No low-level types.
No vhttp::.
No ResponseWrapper.
Just Request and Response.
app.get("/", [](Request req, Response res) {
return json::o("message", "Hello from Vix");
});app.get("/users/{id}", [](Request req, Response res) {
auto id = req.param("id");
return json::o("user_id", id);
});app.get("/search", [](Request req, Response res) {
auto q = req.query_value("q", "none");
auto page = req.query_value("page", "1");
return json::o(
"query", q,
"page", page
);
});app.get("/missing", [](Request req, Response res) {
return std::pair{
404,
json::o("error", "Not found")
};
});app.get("/go", [](Request req, Response res) {
res.redirect("https://vixcpp.com");
});app.get("/forbidden", [](Request req, Response res) {
res.status(403).send();
});app.post("/echo", [](Request req, Response res) {
return json::o(
"received", req.json()
);
});struct UserInput {
std::string name;
int age;
};
app.post("/users", [](Request req, Response res) {
UserInput input = req.json_as<UserInput>();
return std::pair{
201,
json::o(
"name", input.name,
"age", input.age
)
};
});app.get("/headers", [](Request req, Response res) {
res.header("X-App", "Vix")
.type("text/plain")
.send("Hello headers");
});app.get("/state", [](Request req, Response res) {
req.set_state<int>(42);
return json::o(
"value", req.state<int>()
);
});app.get("/manual", [](Request req, Response res) {
res.status(200)
.json(json::o("ok", true));
});app.get("/items/{id}", [](Request req, Response res) {
const auto& params = req.params();
return json::o("id", params.at("id"));
});app.delete("/items/{id}", [](Request req, Response res) {
res.status(204).send();
});#include <vix.hpp>
using namespace vix;
int main()
{
App app;
// Basic JSON response (auto send)
app.get("/", [](Request req, Response res) {
res.send("message", "Hello from Vix");
});
// Path params + return {status, payload}
app.get("/users/{id}", [](Request req, Response res) {
auto id = req.param("id");
return std::pair{200, vix::json::o("id", id)};
});
// Plain text return (const char*)
app.get("/txt", [](const Request&, Response&) {
return "Hello world";
});
// Redirect
app.get("/go", [](Request req, Response res) {
res.redirect("https://vixcpp.com");
});
// Status only → auto message (like Express sendStatus)
app.get("/missing", [](Request req, Response res) {
res.status(404).send();
});
// JSON echo (body → json)
app.post("/echo", [](Request req, Response res) {
return vix::json::o("received", req.json());
});
app.run(8080);
}- Zero magic
- Zero runtime overhead
- Compile-time safety
- Expressive like FastAPI / Express
- Pure modern C++
Vix lets you write business logic, not plumbing.