Composable prefix-grouped routers, CORS policies, per-key sliding-window rate limiters, and request-ID middleware for Veko web apps.
Composable prefix route groups, X-Request-Id tracing middleware, CORS preflight/origin middleware, sliding-window IP rate limiters, and structured JSON access logging for Veko lib/web applications.
veko pkg add http_router@1.2.0Import in any Veko module:
use [rt = http_router]Existing imports of http_router/router remain fully supported via re-exports.
rt/mount-group): Register routes and middlewares onto an isolated sub-web/App, then mount them under any URL prefix ('/api/v1', '/admin') without leaking group middlewares onto public routes.rt/use-request-id validates incoming X-Request-Id headers against header-injection characters or synthesizes a deterministic req-<hex16> trace ID visible to both downstream route handlers (rt/request-id req) and HTTP response headers.rt/use-cors handles OPTIONS preflight requests (204 No Content) and enforces explicit origin allowlists with Vary: Origin.rt/new-rate-limiter and rt/handle-rate-limited track per-IP request timestamps across a rolling window (X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, and 429 Retry-After).CorsConfig — { allow_origins, allow_methods, allow_headers, expose_headers, allow_credentials, max_age_sec }RateLimiter — { max_requests i64, window_sec i64, buckets map }RateDecision — { allowed bool, limit i64, remaining i64, reset_sec i64, retry_after i64 }AccessLogEntry — { method str, path str, status i64, bytes_out i64, client_ip str, request_id str, duration_us i64 }rt/join-paths prefix pattern -> strrt/mount-group mut app prefix register_fn -> web/Apprt/request-id req -> strrt/mw-request-id req next -> web/Response / rt/use-request-id mut apprt/default-cors -> CorsConfigrt/mw-cors cfg -> any / rt/use-cors mut app cfgrt/extract-client-ip req -> strrt/new-rate-limiter max_requests window_sec -> RateLimiterrt/check-rate-limit mut limiter client_key now_sec -> RateDecisionrt/handle-rate-limited mut limiter app req now_sec -> web/Responsert/mw-rate-limit decider_fn -> anyrt/format-access-json entry -> strrt/mw-access-log sink_fn -> any / rt/use-access-log mut app sink_fnuse [rt = http_router, web]
mut app = web/new-app
rt/use-request-id mut app
rt/use-cors mut app (rt/default-cors)
app = rt/mount-group mut app '/api/v1' fn [g web/App] web/App [
mut sub = g
web/get mut sub '/items/:id' fn [req web/Request] web/Response [
web/json-resp 200 {
id = (web/param req 'id' '')
req_id = (rt/request-id req)
}
]
sub
]https://veko-lang.org/pkg/http_router/1.2.0.vkp8f8629a0ff37a7958f884ca805f3447b15381b9aca110009d2b01744ed0c4066be985ebe44e119bcaeec041a12a076e7f888884864a8e3e8a4c44d92c0952c7fed25519:27406074d8681da1d4e6420f5d887cac15c313334c249ac047ba9d4e2df72b70{"name":"http_router","version":"1.2.0","tier":6.0,"tier_label":"Tier 6: Local-First, IoT, Web & Media","category":"Web Routing & Middleware","description":"Composable prefix-grouped routers, CORS policies, per-key sliding-window rate limiters, and request-ID middleware for Veko web apps.","modules":["http_router","http_router/router"],"homepage":"https://veko-lang.org/packages/http_router"}| Bundle Entry Path | Size | Leaf SHA-256 Digest |
|---|---|---|
| README.md | 2 KB | 0a75e8fb2cb804317e9b1bf42356b457992ee2ad22800628f379cdbb5fe78ed7 |
| examples/demo.vk | 6 KB | 5ad050174506d731f317dfee116eea4566b386be5bd75f6f3ad3207bcdf1e377 |
| mod.vk | 11 KB | f2cf0cb5b49cca137b8a90d341633d4868fe171152a3eed26012535ed696c74a |
| router.vk | 1 KB | be6411e096797aa8e27b9dc7b44d33876ed0a4d048c56c98c3d7bee64fd263a5 |