How to Access the Request Object in Mitsuki Controllers
dev.to·4d·
Discuss: DEV
🔌APIs
Preview
Report Post

In Mitsuki, you’d usually work abstractions like @QueryParam and RequestBody that handle the details of HTTP requests for you. However, sometimes you need to access the raw request object to read headers, inspect client details, or manage cookies.

This guide shows you how to directly access the underlying starlette.requests.Request object in your controller methods.

The Request Type Hint

The easiest way to get the request object is to add a parameter to your controller method and type-hint it as Request. Mitsuki’s dependency injection system will automatically provide the object for you.

Here’s how you can inject the request to read its properties:

from mitsuki import RestController, GetMapping
from starlette.requests import Request

@RestController("/api")
clas...

Similar Posts

Loading similar posts...