C++ Templates · Serving

Serving

17035008

Ask your coding agent about this page, or add the docs server to it

curl -s 'https://www.unum.cloud/docs/ucall/templates/serving.md' | claude -p "How would this fit my code?"

§ Routing Requests

route_trie_t matches a path against URI templates, literals before parameters before a trailing wildcard, and answers the endpoint registered for the verb:

#include "ucall/http/routes.hpp" // `route_trie_t`

namespace uc = unum::ucall;

static int greet = 0; // any address names an endpoint

int main() {
    uc::http::route_trie_t routes {uc::st::default_allocator<uc::http::byte_t> {}};
    if (routes.init() != ucall_status_success_k) return 1;
    // The trie keeps the views it was handed, so a template outlives the trie, as this literal does.
    if (routes.insert("/hello/{name}", ucall_verb_get_k, &greet) != ucall_status_success_k) return 1;
    // A query and a fragment never take part in matching.
    return routes.match("/hello/world?lang=en", ucall_verb_get_k) == &greet ? 0 : 1;
}