nx_http_router.nx
buildroot/runtime/nx_http_router.nx
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
imports: nx_syscalls.nxnx_tier.nx
imported by: nx_http_router_test.nx
structs
| 82 | struct HttpRouter |
consts
| 42 | const NX_HTTP_METHOD_UNKNOWN: nx_int = 0 |
| 43 | const NX_HTTP_METHOD_GET: nx_int = 1 |
| 44 | const NX_HTTP_METHOD_POST: nx_int = 2 |
| 45 | const NX_HTTP_METHOD_OPTIONS: nx_int = 3 |
| 46 | const NX_HTTP_METHOD_PUT: nx_int = 4 |
| 47 | const NX_HTTP_METHOD_DELETE: nx_int = 5 |
| 48 | const NX_HTTP_METHOD_PATCH: nx_int = 6 |
| 49 | const NX_HTTP_METHOD_HEAD: nx_int = 7 |
| 50 | const NX_HTTP_METHOD_ANY: nx_int = 8 // wildcard |
| 51 | const NX_HTTP_METHOD_N_KINDS: nx_int = 9 |
| 61 | const NX_HTTP_MATCH_EXACT: nx_int = 0 |
| 62 | const NX_HTTP_MATCH_PREFIX: nx_int = 1 |
| 63 | const NX_HTTP_MATCH_N_KINDS: nx_int = 2 |
| 71 | const NX_ROUTE_F_METHOD: nx_int = 0 |
| 72 | const NX_ROUTE_F_MATCH_KIND: nx_int = 1 |
| 73 | const NX_ROUTE_F_PATTERN_PTR: nx_int = 2 |
| 74 | const NX_ROUTE_F_PATTERN_LEN: nx_int = 3 |
| 75 | const NX_ROUTE_F_HANDLER_ID: nx_int = 4 |
| 76 | const NX_ROUTE_FIELDS: nx_int = 5 |
| 88 | const NX_HTTP_ROUTER_BYTES: nx_int = 24 |
functions
| 53 | func nx_http_method_is_valid(m: nx_int) -> nx_int |
| 90 | func nx_http_router_alloc(cap: nx_int) -> *HttpRouter |
| 104 | func nx_http_router_add(r: *HttpRouter, |
| 123 | func _hr_bytes_eq(a: *u8, b: *u8, n: nx_int) -> nx_int called by 1: nx_http_router_match |
| 139 | func nx_http_router_match(r: *HttpRouter, |
| 185 | func nx_http_router_suffix_offset(matched_prefix_len: nx_int) -> nx_int called by 1: main |