Handling Requests
In LightAPI v2, the request parameter in method overrides is a standard Starlette Request object.
JSON Payloads
For POST, PUT, and PATCH overrides, read the body with await request.body() (async) or request.body() in sync methods, then parse as JSON:
You can also use await request.json() as a shorthand for async handlers:
Path Parameters
Detail routes (/items/{id}) pass pk directly to the handler — you rarely need to read it from the request. If you need it manually:
Query Parameters
Query parameters are available via request.query_params (a QueryParams mapping):
async def get(self, request):
page = request.query_params.get("page", "1")
search = request.query_params.get("search", "")
For automatic filtering and pagination, use Meta.filtering and Meta.pagination instead of manual query parameter parsing.
Request Headers
async def get(self, request):
auth_header = request.headers.get("Authorization")
content_type = request.headers.get("Content-Type")
user_agent = request.headers.get("User-Agent")
Authenticated user
When JWTAuthentication is configured, the decoded token payload is stored in request.state.user after successful authentication:
async def post(self, request):
user = request.state.user # dict from JWT payload
user_id = user.get("sub")
data = await request.json()
data["author_id"] = int(user_id)
return await self._create_async(data)