new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

FastAPI · Reference · all subjects

request & response classes

4 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Request object import and usage

The Request class can be imported from fastapi.requests or starlette.requests. FastAPI provides it directly as a convenience, though it originates from Starlette. To use the Request object directly, declare a path operation function parameter with the type Request, and FastAPI will pass the Request object to that parameter.

Request object direct access skips validation and OpenAPI documentation

When you access data directly from the Request object (such as reading its body), that data is not validated, converted, or documented by FastAPI (with OpenAPI). However, other normally declared parameters (such as the body with a Pydantic model) will still be validated, converted, and annotated.

Request object use case for client information

The Request object is useful for accessing client information directly, such as the client's IP address or host, which may not be available through standard FastAPI parameter declarations.

Custom Request class to override Request.body()

You can create a custom Request subclass to override the Request.body() method. This allows you to manipulate the request body before it is processed by the application, such as decompressing gzip-compressed request bodies. A custom Request subclass receives the scope and receive parameters from the original Request instance, both of which are part of the ASGI specification.

Give your agent this brain