コンテンツにスキップ
per page, with , order by , clip by
Results of 1 - 10 of about 31 for parameter (0.001 sec.)
Using the Request Directly 13815
Using the Request Directly Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . Up to now, you have been declaring the parts of the request that you need with their typ ... es. Taking data from: The path as parameters. Headers. Cookies. etc. And by doing so, FastAPI is validating that data, converting it and generating documentation for ... be validated, converted or documented (with OpenAPI, for the automatic API user interface) by FastAPI. Although any other parameter declared normally (for example, the body with a Pydantic model) would still be validated, converted, annotated, etc. But t ... equest . client . host return { "client_host" : client_host , "item_id" : item_id } By declaring a path operation function parameter with the type being the Request FastAPI will know to pass the Request in that parameter. Tip Note that in this case, we ar ...
https://man.mtool.work/fastapi/0.115/advanced/using-request-directly/
Response Headers 11405
Response Headers Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . Use a Response parameter You can declare a parameter of type Response in your path operation funct ... he final response that contains the value you returned, filtered by any response_model . You can also declare the Response parameter in dependencies, and set headers (and cookies) in them. Return a Response directly You can also add headers when you retur ... n a Response directly. Create a response as described in Return a Response Directly and pass the headers as an additional parameter: Python 3.8+ from fastapi import FastAPI from fastapi.responses import JSONResponse app = FastAPI () @app . get ( "/header ... e to see, you need to add them to your CORS configurations (read more in CORS (Cross-Origin Resource Sharing) ), using the parameter expose_headers documented in Starlette's CORS docs . ...
https://man.mtool.work/fastapi/0.115/advanced/response-headers/
Response - Change Status Code 10677
Response - Change Status Code Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . You probably read before that you can set a default Response Status Code . But in som ... want to be able to filter and convert the data you return with a response_model . For those cases, you can use a Response parameter. Use a Response parameter You can declare a parameter of type Response in your path operation function (as you can do for ... he final response that contains the value you returned, filtered by any response_model . You can also declare the Response parameter in dependencies, and set the status code in them. But keep in mind that the last one to be set will win. ...
https://man.mtool.work/fastapi/0.115/advanced/response-change-status-code/
Response Cookies 10256
Response Cookies Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . Use a Response parameter You can declare a parameter of type Response in your path operation funct ... he final response that contains the value you returned, filtered by any response_model . You can also declare the Response parameter in dependencies, and set cookies (and headers) in them. Return a Response directly You can also create cookies when return ... kie-session-value" ) return response Tip Keep in mind that if you return a response directly instead of using the Response parameter, FastAPI will return it directly. So, you will have to make sure your data is of the correct type. E.g. it is compatible w ... can be used frequently to set headers and cookies, FastAPI also provides it at fastapi.Response . To see all the available parameters and options, check the documentation in Starlette . ...
https://man.mtool.work/fastapi/0.115/advanced/response-cookies/
Request class 9722
Request class You can declare a parameter in a path operation function or dependency to be of type Request and then you can access the raw request object directly, without any validation, etc. You can import it directly from fastapi : from ... Request Tip When you want to define dependencies that should be compatible with both HTTP and WebSockets, you can define a parameter that takes an HTTPConnection instead of a Request or a WebSocket . ::: fastapi.Request ...
https://man.mtool.work/fastapi/0.115/reference/request/
WebSockets 8897
WebSockets When defining WebSockets, you normally declare a parameter of type WebSocket and with it you can read data from the client and send data to it. It is provided directly by Starlette, but you can import it from fastapi : from fasta ... bSocket Tip When you want to define dependencies that should be compatible with both HTTP and WebSockets, you can define a parameter that takes an HTTPConnection instead of a Request or a WebSocket . ::: fastapi.WebSocket options: members: - scope - app - ...
https://man.mtool.work/fastapi/0.115/reference/websockets/
Additional Responses in OpenAPI 8363
Additional Responses in OpenAPI Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . Warning This is a rather advanced topic. If you are starting with FastAPI , you mig ... rectly, with your status code and content. Additional Response with model You can pass to your path operation decorators a parameter responses . It receives a dict : the keys are status codes for each response (like 200 ), and the values are other dict s ... onents/schemas/ValidationError" } } } } } } } Additional media types for the main response You can use this same responses parameter to add different media types for the same main response. For example, you can add an additional media type of image/png , ... eturn the image using a FileResponse directly. Info Unless you specify a different media type explicitly in your responses parameter, FastAPI will assume the response has the same media type as the main response class (default application/json ). But if y ...
https://man.mtool.work/fastapi/0.115/advanced/additional-responses/
Using Dataclasses 8363
Using Dataclasses Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . FastAPI is built on top of Pydantic , and I have been showing you how to use Pydantic models to d ... them to power a web API using FastAPI. ? Dataclasses in response_model You can also use dataclasses in the response_model parameter: Python 3.8+ from dataclasses import dataclass , field from typing import List , Union from fastapi import FastAPI @datacl ... dataclasses . The Author dataclass includes a list of Item dataclasses. The Author dataclass is used as the response_model parameter. You can use other standard type annotations with dataclasses as the request body. In this case, it's a list of Item datac ... urning dataclasses (although it could), but a list of dictionaries with internal data. FastAPI will use the response_model parameter (that includes dataclasses) to convert the response. You can combine dataclasses with other type annotations in many diffe ...
https://man.mtool.work/fastapi/0.115/advanced/dataclasses/
Lifespan Events 8363
Lifespan Events Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . You can define logic (code) that should be executed before the application starts up . This means t ... g requests, not while the code is being loaded. Lifespan You can define this startup and shutdown logic using the lifespan parameter of the FastAPI app, and a "context manager" (I'll show you what that is in a second). Let's start with an example and then ... the yield . In our code example above, we don't use it directly, but we pass it to FastAPI for it to use it. The lifespan parameter of the FastAPI app takes an async context manager , so we can pass our new lifespan async context manager to it. Python 3. ... ult } Alternative Events (deprecated) Warning The recommended way to handle the startup and shutdown is using the lifespan parameter of the FastAPI app as described above. If you provide a lifespan parameter, startup and shutdown event handlers will no lo ...
https://man.mtool.work/fastapi/0.115/advanced/events/
OpenAPI Callbacks 8153
OpenAPI Callbacks Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . You could create an API with a path operation that could trigger a request to an external API cre ... p would look like before adding the callback. It will have a path operation that will receive an Invoice body, and a query parameter callback_url that will contain the URL for the callback. This part is pretty normal, most of the code is probably already ... , collect the money, send the notification (the callback) return { "msg" : "Invoice received" } Tip The callback_url query parameter uses a Pydantic Url type. The only new thing is the callbacks=invoices_callback_router.routes as an argument to the path o ... orarily adopting this point of view (of the external developer ) can help you feel like it's more obvious where to put the parameters, the Pydantic model for the body, for the response, etc. for that external API . Create a callback APIRouter First create ...
https://man.mtool.work/fastapi/0.115/advanced/openapi-callbacks/
PREV 1 2 3 4 NEXT