Paozhu logo Paozhu Docs
Documentation
START

Hello World

One annotation registers the route; one function returns the response.

Create a controller

Put the following function in controller/src/myhello.cpp. The header controller/include/myhello.h is generated at CMake configure time. During build, paozhu_pre scans annotations and writes routes into common/autocontrolmethod.hpp.

controller/src/myhello.cppcpp
#include "httppeer.h"
#include "myhello.h"

namespace http
{
//@urlpath(null,myhello)
asio::awaitable<std::string> myhello(std::shared_ptr<httppeer> peer)
{
    peer->output = "Hello from myhello!";
    co_return "";
}
}

Rebuild, start the server and open http://127.0.0.1/myhello; the page shows Hello from myhello!. The repository example is controller/src/testhello.cpp, exposed at /hello.

Annotation syntax

annotation formattext
//@urlpath(pre_filter, /path/:param):maskcode(1234):ratelimit(20,5):title("Page title")

// pre_filter  -> function name, or null for none
// /path/:param -> route; :param must be trailing
// maskcode(n) -> RBAC mask, 0 means the auth hook is skipped
// ratelimit(n,s) -> per-route rate limit
// title(...)   -> shown in the permission catalogue
PartMeaningExample
nullNo pre-filter//@urlpath(null,hello)
Filter nameRuns first; @ok continuesadmin_islogin
:maskcodeRBAC mask; 0 skips the hook:maskcode(64)
:ratelimitPer-route rate limit:ratelimit(20,5)
:titleDisplay name in permission catalogue:title("Article list")

Coroutine and sync handlers

Returning asio::awaitable<std::string> is recommended when you need co_await for async ORM or HTTP calls. A sync handler returning std::string also works — the stress-test route in the repo uses that form.

controller/src/hello_sync.cppcpp
//@urlpath(null,hello/sync)
std::string hello_sync(std::shared_ptr<httppeer> peer)
{
    httppeer &client = peer->get_peer();
    client << "Hello from a sync handler";
    return "";
}

Read a path parameter

controller/src/user_info.cppcpp
//@urlpath(null,user/info/:userid)
std::string user_info(std::shared_ptr<httppeer> peer)
{
    httppeer &client = peer->get_peer();
    client << "userid: " << client.get["userid"].to_string();
    return "";
}

For /user/info/42, client.get["userid"] is 42. Query-string parameters also come from client.get; POST fields come from client.post.

Four common outputs

GoalCode
Plain text / HTMLpeer->output = "..."; or client << "..."
JSONclient.val["code"] = 0; client.out_json();
Template viewpeer->view("cms/list");
Redirectclient.goto_url("/admin/main");