Skip to content

Routing & Controllers

Zuno uses a clean, expressive routing system inspired by frameworks like Express.js. You can define routes directly in your main.cpp, or organize them into modular controllers for larger applications.


Zuno supports standard HTTP methods: GET, POST, PUT, DELETE, and more.

app.get("/", [](auto& req, auto& res) {
res.send("Hello from Zuno!");
});
app.post("/submit", [](auto& req, auto& res) {
res.send("Data received!");
});

You can define dynamic segments in your routes using :param.

app.get("/users/:id", [](auto& req, auto& res) {
std::string userId = req.params["id"];
res.send("User ID: " + userId);
});

Access query parameters via req.query.

app.get("/search", [](auto& req, auto& res) {
std::string term = req.query("q");
res.send("Searching for: " + term);
});

For POST and PUT autos, you can access the body as a string or parse it as JSON.

app.post("/echo", [](auto& req, auto& res) {
res.send("You sent: " + req.body());
});

JSON parsing helpers are coming soon as part of the utilities module.


For larger apps, you can organize routes into separate files or modules.

#include <zuno/zuno.hpp>
void registerUserRoutes(zuno::App& app) {
app.get("/users", [](auto& req, auto& res) {
res.send("User list");
});
app.get("/users/:id", [](auto& req, auto& res) {
res.send("User ID: " + req.params["id"]);
});
}
#include <zuno/zuno.hpp>
#include "routes/users.hpp"
int main() {
zuno::App app;
registerUserRoutes(app);
app.listen(3000);
}

Now that you’ve mastered routing, you can:


Zuno’s routing system is fast, flexible, and built for modern C++.