code wiki / (root) / nx_http_router.nx

nx_http_router.nx

buildroot/runtime/nx_http_router.nx

6883 B187 linesdepth 2pulls 2 transitivereach 1 importersview sourcekind librarytopic http
docsdependenciesstructsconstsfunctions

about

nx_http_router.nx -- method+path route dispatch table. Final missing piece for porting an Elder AI service to NishiLang. Existing substrate: nx_http.nx -- request parser (64-header HttpRequest struct) nx_http_io.nx -- minimal server-side parse + write nx_http_resp.nx -- response builder nx_http_client.nx -- HTTP client (outbound) nx_http_date.nx -- date formatter nx_syscalls + nx_syscalls_x86_64 -- socket bind/listen/accept This module adds the dispatch layer: a Route table of (method, path_pattern, handler_id) triples, and a match function that returns the handler_id for an incoming (method, path). NishiLang doesn't have first-class function pointers, so the caller dispatches on handler_id via switch-style if/else chain. Same pattern Flask + Express + FastAPI use internally before the reflection layer. Path matching v1: exact match or prefix match (controlled per-route). Path parameters (e.g. /api/character/:id) queued for v2 -- v1 routes match prefix and let the handler peel the remainder. genealogy_id: flask_routing + express_dispatch + actix_web_routes lineage_id: substrate_http_router_v1

dependencies 2 imports · 1 importers

nx_syscalls.nx nx_tier.nx nx_http_router.nx nx_http_router_test.nx

imports: nx_syscalls.nxnx_tier.nx

imported by: nx_http_router_test.nx

structs

82struct HttpRouter

consts

42const NX_HTTP_METHOD_UNKNOWN: nx_int = 0
43const NX_HTTP_METHOD_GET: nx_int = 1
44const NX_HTTP_METHOD_POST: nx_int = 2
45const NX_HTTP_METHOD_OPTIONS: nx_int = 3
46const NX_HTTP_METHOD_PUT: nx_int = 4
47const NX_HTTP_METHOD_DELETE: nx_int = 5
48const NX_HTTP_METHOD_PATCH: nx_int = 6
49const NX_HTTP_METHOD_HEAD: nx_int = 7
50const NX_HTTP_METHOD_ANY: nx_int = 8 // wildcard
51const NX_HTTP_METHOD_N_KINDS: nx_int = 9
61const NX_HTTP_MATCH_EXACT: nx_int = 0
62const NX_HTTP_MATCH_PREFIX: nx_int = 1
63const NX_HTTP_MATCH_N_KINDS: nx_int = 2
71const NX_ROUTE_F_METHOD: nx_int = 0
72const NX_ROUTE_F_MATCH_KIND: nx_int = 1
73const NX_ROUTE_F_PATTERN_PTR: nx_int = 2
74const NX_ROUTE_F_PATTERN_LEN: nx_int = 3
75const NX_ROUTE_F_HANDLER_ID: nx_int = 4
76const NX_ROUTE_FIELDS: nx_int = 5
88const NX_HTTP_ROUTER_BYTES: nx_int = 24

functions

53func nx_http_method_is_valid(m: nx_int) -> nx_int
90func nx_http_router_alloc(cap: nx_int) -> *HttpRouter
called by 1: main calls 1: sys_mmap
104func nx_http_router_add(r: *HttpRouter,
called by 1: main calls 1: nx_http_method_is_valid
123func _hr_bytes_eq(a: *u8, b: *u8, n: nx_int) -> nx_int
139func nx_http_router_match(r: *HttpRouter,
called by 1: main calls 1: _hr_bytes_eq
185func nx_http_router_suffix_offset(matched_prefix_len: nx_int) -> nx_int
called by 1: main