Skip to content

Generated by sema doc from stdlib/sema/web.sema. Import with from std.web import …. For a narrative introduction see std.web.

std.web — a tiny FastAPI-shaped HTTP layer over the native http.serve seam (§5.34).

Framework ergonomics without a framework: write handlers (req) -> Response, register them on a Router by method + path (with {param} path segments), and serve. The request is the native dict {method, path, query, body, headers} (headers lowercased) plus a params dict of captured path segments. A handler returns a Response built with the ok/json_status/text/error helpers.

from std.web import router, get, post, serve, ok, error
def health(req: dict) -> Response !{}:
return ok({"status": "ok"})
def serve_api(port: int) -> None !{net.listen}:
app = router()
get(app, "/healthz", health)
post(app, "/search", search_handler)
serve(app, port)

serve/dispatch carry the standard web effect envelope (net + model + fs + clock + observe + ffi + env), so a handler may perform any of those; the caller declares the same (or wider) row. A true @get("/path") decorator that registers at load time needs a runtime hook (like @provides) and is a deferred SDK add — explicit registration is the reliable, framework-free equivalent.

Fields

fieldtypedescriptor
statusint
content_typestr
headersdict
bodystr

Fields

fieldtypedescriptor
methodstr
pathstr
handlerany

Fields

fieldtypedescriptor
routeslist[Route]
def router() -> Router !{}

Returns Router

Effects !{}

def route(app: Router, method: str, path: str, handler: any) -> Router !{}

Parameters

nametype
appRouter
methodstr
pathstr
handlerany

Returns Router

Effects !{}

def get(app: Router, path: str, handler: any) -> Router !{}

Parameters

nametype
appRouter
pathstr
handlerany

Returns Router

Effects !{}

def post(app: Router, path: str, handler: any) -> Router !{}

Parameters

nametype
appRouter
pathstr
handlerany

Returns Router

Effects !{}

def put(app: Router, path: str, handler: any) -> Router !{}

Parameters

nametype
appRouter
pathstr
handlerany

Returns Router

Effects !{}

def delete(app: Router, path: str, handler: any) -> Router !{}

Parameters

nametype
appRouter
pathstr
handlerany

Returns Router

Effects !{}

def patch(app: Router, path: str, handler: any) -> Router !{}

Parameters

nametype
appRouter
pathstr
handlerany

Returns Router

Effects !{}

def response(status: int, content_type: str, body: str) -> Response !{}

Parameters

nametype
statusint
content_typestr
bodystr

Returns Response

Effects !{}

def ok(obj: any) -> Response !{}

Parameters

nametype
objany

Returns Response

Effects !{}

def json_status(status: int, obj: any) -> Response !{}

Parameters

nametype
statusint
objany

Returns Response

Effects !{}

def text(body: str) -> Response !{}

Parameters

nametype
bodystr

Returns Response

Effects !{}

def error(status: int, message: str) -> Response !{}

Parameters

nametype
statusint
messagestr

Returns Response

Effects !{}

def header(r: Response, name: str, value: str) -> Response !{}

Parameters

nametype
rResponse
namestr
valuestr

Returns Response

Effects !{}

def clean_path(path: str) -> str !{}

Parameters

nametype
pathstr

Returns str

Effects !{}

def match_path(pattern: str, actual: str) -> any !{}

Parameters

nametype
patternstr
actualstr

Returns any

Effects !{}

def resp_dict(r: Response) -> dict !{}

Parameters

nametype
rResponse

Returns dict

Effects !{}

def dispatch(app: Router, req: dict) -> dict !{net.connect, model.invoke, model.embed, fs.read, clock, observe.record, ffi.call, env.read}

Parameters

nametype
appRouter
reqdict

Returns dict

Effects !{net.connect, model.invoke, model.embed, fs.read, clock, observe.record, ffi.call, env.read}

def serve(app: Router, port: int) -> None !{net.listen, net.connect, model.invoke, model.embed, fs.read, clock, observe.record, ffi.call, env.read}

Parameters

nametype
appRouter
portint

Returns None

Effects !{net.listen, net.connect, model.invoke, model.embed, fs.read, clock, observe.record, ffi.call, env.read}

def serve_on(app: Router, host: str, port: int) -> None !{net.listen, net.connect, model.invoke, model.embed, fs.read, clock, observe.record, ffi.call, env.read}

Parameters

nametype
appRouter
hoststr
portint

Returns None

Effects !{net.listen, net.connect, model.invoke, model.embed, fs.read, clock, observe.record, ffi.call, env.read}