justapi — /docs

Custom Request Class

JustAPI's routing is fully native (Rust matchit), so there is no replaceable APIRoute/route_class mechanism — routes are registered on JustAPIApp. You can subclass justapi.Request and accept it as a parameter to customize how a handler reads the request.

from justapi import JustAPIApp, Request

class CustomRequest(Request):
    async def json(self):
        body = await super().json()
        # pre-process the body before application logic
        return body

app = JustAPIApp()

@app.post("/items")
async def create_item(request: CustomRequest):
    data = await request.json()
    return data

For per-route cross-cutting behavior (timing, auth, header injection), use the native middleware mechanisms instead:

import time
from justapi import JustAPIApp

app = JustAPIApp()

@app.middleware("http")
async def timing(request, call_next):
    start = time.time()
    response = await call_next(request)
    response.headers["X-Process-Time"] = str(round(time.time() - start, 4))
    return response

See Also

JustAPI v2.0.9 — Open Source MIT License · Built with WebTUI · GitHub

NORMAL master justapi/docs
utf-8 Top 1:1