Module <cweb/routing.h> — routing
Registration of path → handler mappings and options for sessions and dynamic paths.
Type route_handler_t
typedef void (*route_handler_t)(Request *req, Response *res);
Each handler parses req as needed, fills res, and returns control (for synchronous handlers); asynchronous responses use pending/fetch paths.
Type Route
Contains among other fields registered path, handler, flags for session, dynamic subpaths, and path parameters.
Functions
void cweb_set_fallback_handler(route_handler_t handler)
- Purpose: Handler invoked when no explicit route matches (404 fallback or central app logic).
void cweb_set_dynamic_subpath(char *path, int set_dynamic)
- Purpose: Marks a route as “has dynamic subpath” for matching (internal routing — exact semantics in routing module).
void cweb_set_dynamic_param(char *path, int set_dynamic)
- Purpose: Enables/disables placeholders/parameters in the path (REST parameters).
int cweb_rewriteRoutePath(char *current_path, char *new_path)
- Purpose: Path rewriting (typically internal or for redirects); modifies the passed buffers per implementation.
- Return: status code (
0= success).
void cweb_add_route(const char *path, route_handler_t handler, bool requires_session)
- Purpose: Registers a route.
- Parameters:
path— URL path (follow framework conventions for trailing slash).handler— function pointer.requires_session— whentrue, the framework expects a valid session (cookie or similar).
route_handler_t cweb_get_route_handler(const char *path, bool *requires_session)
- Purpose: Looks up handler for a requested path.
- Parameters:
requires_session— output whether route requires session. - Return: handler or
NULLif none matches.
void cweb_clear_routes(void)
- Purpose: Removes all registered routes (e.g. for tests or restart).
See also
- pathutils.md — query and path parameters
- server.md — connection to incoming requests
- session.md —
requires_session