Using the Request Directly
Accessing the Request
Section titled “Accessing the Request”Any handler can receive the raw Request object as a parameter:
from starlette.requests import Requestfrom justapi import JustAPIApp
app = JustAPIApp()
@app.get("/info")def get_info(request: Request): return { "method": request.method, "url": str(request.url), "client": request.client.host if request.client else None, }Reading Headers
Section titled “Reading Headers”@app.get("/headers")def get_headers(request: Request): return { "user_agent": request.headers.get("user-agent"), "accept": request.headers.get("accept"), "authorization": request.headers.get("authorization", "none"), }Reading Body
Section titled “Reading Body”@app.post("/raw-body")async def raw_body(request: Request): body = await request.body() return {"size": len(body), "content": body.decode()}Path and Query Info
Section titled “Path and Query Info”@app.get("/request-info")def request_info(request: Request): return { "path": request.url.path, "query": str(request.query_params), "path_params": dict(request.path_params), }See Also
Section titled “See Also”- Path Parameters — extracting path params
- Header Parameters — typed header access
- Cookie Parameters — typed cookie access