Results of 1 - 10 of about 37 for request (0.003 sec.)
- Custom Request and APIRoute class 13070
- Custom Request and APIRoute class Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . In some cases, you may want to override the logic used by the Request and APIRout
...In particular, this may be a good alternative to logic in a middleware. For example, if you want to read or manipulate the request body before it is processed by your application. Danger This is an "advanced" feature. If you are just starting with FastA...PI you might want to skip this section. Use cases Some use cases include: Converting non-JSON request bodies to JSON (e.g. msgpack ). Decompressing gzip-compressed request bodies. Automatically logging all request bodies. Ha...ndling custom request body encodings Let's see how to make use of a custom Request subclass to decompress gzip requests. And an APIRoute subclas... - https://man.mtool.work/fastapi/0.115/how-to/custom-request-and-route/
- Using the Request Directly 11934
- 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
...ng it and generating documentation for your API automatically. But there are situations where you might need to access the Request object directly. Details about the Request object As FastAPI is actually Starlette underneath, with a layer of several too...ls on top, you can use Starlette's Request object directly when you need to. It would also mean that if you get data from the Request object directly (for example, r...ntic model) would still be validated, converted, annotated, etc. But there are specific cases where it's useful to get the Request object. Use the Request object directly Let's imagine you want to get the client's IP address/host inside of your path ope... - https://man.mtool.work/fastapi/0.115/advanced/using-request-directly/
- Request class 10355
- 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
...fastapi import Request Tip When you want to define dependencies that should be compatible with both HTTP and WebSockets, you can define a paramet...er that takes an HTTPConnection instead of a Request or a WebSocket . ::: fastapi.Request... - https://man.mtool.work/fastapi/0.115/reference/request/
- Behind a Proxy 10245
- Behind a Proxy Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . In some situations, you might need to use a proxy server like Traefik or Nginx with a configuration
.../api/v1/app . Even though all your code is written assuming there's just /app . Python 3.8+ from fastapi import FastAPI , Request app = FastAPI () @app . get ( "/app" ) def read_main ( request : Request ): return { "message" : "Hello World" , "root_pat...h" : request . scope . get ( "root_path" )} And the proxy would be "stripping" the path prefix on the fly before transmitting the reque...ovides that root_path . Checking the current root_path You can get the current root_path used by your application for each request, it is part of the scope dictionary (that's part of the ASGI spec). Here we are including it in the message just for demon... - https://man.mtool.work/fastapi/0.115/advanced/behind-a-proxy/
- OpenAPI Callbacks 10166
- 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
...your API app calls the external API is named a "callback". Because the software that the external developer wrote sends a request to your API and then your API calls back , sending a request to an external API (that was probably created by the same dev...ional), customer , and total . The user of your API (an external developer) will create an invoice in your API with a POST request. Then your API will (let's imagine): Send the invoice to some customer of the external developer. Collect the money. Send...a notification back to the API user (the external developer). This will be done by sending a POST request (from your API ) to some external API provided by that external developer (this is the "callback"). The normal FastAPI app... - https://man.mtool.work/fastapi/0.115/advanced/openapi-callbacks/
- ミドルウェア 10134
- ミドルウェア FastAPI アプリケーションにミドルウェアを追加できます。 「ミドルウェア」は、すべての リクエスト に対して、それがあらゆる特定の path operation によって処理される前に機能する関数です。また、すべての レスポンス に対して、それを返す
...ルウェアを作成するには、関数の上部でデコレータ @app.middleware("http") を使用します。 ミドルウェア関数は以下を受け取ります: request 。 パラメータとして request を受け取る関数 call_next 。 この関数は、対応する path operation に request を渡します。 次に、...その後、 response を返す前にさらに response を変更することもできます。 Python 3.8+ import time from fastapi import FastAPI , Request app = FastAPI () @app . middleware ( "http" ) async def add_process_time_header ( request : Request , call_next ): start_t...ime = time . perf_counter () response = await call_next ( request ) process_time = time . perf_counter () - start_time response . headers [ "X-Process-Time" ] = str ( process_time ) return... - https://man.mtool.work/fastapi/0.115/tutorial/middleware/
- Templates 9203
- Templates Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . You can use any template engine you want with FastAPI . A common choice is Jinja2, the same one used by F
...ja2 ---> 100% Using Jinja2Templates Import Jinja2Templates . Create a templates object that you can reuse later. Declare a Request parameter in the path operation that will return a template. Use the templates you created to render and return a Template...Response , pass the name of the template, the request object, and a "context" dictionary with key-value pairs to be used inside of the Jinja2 template. Python 3.8+ from fastapi...import FastAPI , Request from fastapi.responses import HTMLResponse from fastapi.staticfiles import StaticFiles from fastapi.templating import Jinj... - https://man.mtool.work/fastapi/0.115/advanced/templates/
- エラーハンドリング 9061
- エラーハンドリング APIを使用しているクライアントにエラーを通知する必要がある状況はたくさんあります。 このクライアントは、フロントエンドを持つブラウザ、誰かのコード、IoTデバイスなどが考えられます。 クライアントに以下のようなことを伝える必要が
...います。 カスタム例外ハンドラを @app.exception_handler() で追加することができます: Python 3.8+ from fastapi import FastAPI , Request from fastapi.responses import JSONResponse class UnicornException ( Exception ): def __init__ ( self , name : str ): self.... name = name app = FastAPI () @app . exception_handler ( UnicornException ) async def unicorn_exception_handler ( request : Request , exc : UnicornException ): return JSONResponse ( status_code = 418 , content = { "message" : f "Oops! { exc . n...を受け取ることになります: { "message" : "Oops! yolo did something. There goes a rainbow..." } 技術詳細 また、 from starlette.requests import Request と from starlette.responses import JSONResponse を使用することもできます。 FastAPI は開発者の利便性を考慮し... - https://man.mtool.work/fastapi/0.115/tutorial/handling-errors/
- Release Notes 8887
- Release Notes Latest Changes 0.115.11 Fixes ? Add docs examples and tests (support) for Annotated custom validations, like AfterValidator , revert #13440 . PR #13442 by @tiangolo . New docs: Query Parameters and String Validations - Custom
...ation for docs/vi/docs/deployment/index.md . PR #13405 by @ptt3199 . ? Add Ukrainian translation for docs/uk/docs/tutorial/request-forms.md . PR #13383 by @valentinDruzhinin . ? Add Ukrainian translation for docs/uk/docs/tutorial/testing.md . PR #13371...k/docs/tutorial/header-params.md . PR #13381 by @valentinDruzhinin . ? Add Ukrainian translation for docs/uk/docs/tutorial/request-files.md . PR #13395 by @valentinDruzhinin . ? Add Ukrainian translation for docs/uk/docs/tutorial/request-form-models.md.... PR #13384 by @valentinDruzhinin . ? Add Ukrainian translation for docs/uk/docs/tutorial/request-forms-and-files.md . PR #13386 by @valentinDruzhinin . ? Update Korean translation for docs/ko/docs/help-fastapi.md . PR #... - https://man.mtool.work/fastapi/0.115/release-notes/
- Request Parameters 8382
- Request Parameters Here's the reference information for the request parameters. These are the special functions that you can put in path operation function parameters or dependency functions with Annotated to get data from the request. It i
... - https://man.mtool.work/fastapi/0.115/reference/parameters/