Results of 1 - 6 of about 6 for handler (0.003 sec.)
- Custom Request and APIRoute class 12685
- 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
..." ): body = gzip . decompress ( body ) self . _body = body return self . _body class GzipRoute ( APIRoute ): def get_route_handler ( self ) -> Callable : original_route_handler = super () . get_route_handler () async def custom_route_handler ( request :...Request ) -> Response : request = GzipRequest ( request . scope , request . receive ) return await original_route_handler ( request ) return custom_route_handler app = FastAPI () app . router . route_class = GzipRoute @app . post ( "/sum" ) asy...astapi.routing.APIRoute that will make use of the GzipRequest . This time, it will overwrite the method APIRoute.get_route_handler() . This method returns a function. And that function is what will receive a request and return a response. Here we use it... - https://man.mtool.work/fastapi/0.115/how-to/custom-request-and-route/
- エラーハンドリング 10382
- エラーハンドリング APIを使用しているクライアントにエラーを通知する必要がある状況はたくさんあります。 このクライアントは、フロントエンドを持つブラウザ、誰かのコード、IoTデバイスなどが考えられます。 クライアントに以下のようなことを伝える必要が
...n があるとしましょう。 そして、この例外をFastAPIでグローバルに処理したいと思います。 カスタム例外ハンドラを @app.exception_handler() で追加することができます: Python 3.8+ from fastapi import FastAPI , Request from fastapi.responses import JSONResponse c...s 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 JSONRespon.../unicorns/yolo をリクエストすると、 path operation は UnicornException を raise します。 しかし、これは unicorn_exception_handler で処理されます。 そのため、HTTPステータスコードが 418 で、JSONの内容が以下のような明確なエラーを受け取ることになります: {... - https://man.mtool.work/fastapi/0.115/tutorial/handling-errors/
- yieldを持つ依存関係 8116
- yieldを持つ依存関係 FastAPIは、いくつかの 終了後の追加のステップ を行う依存関係をサポートしています。 これを行うには、 return の代わりに yield を使い、その後に追加のステップを書きます。 豆知識 yield は必ず一度だけ使用するようにしてください。
...各列はコードを相互作用させたり、実行したりしている部分の一つです。 sequenceDiagram participant client as Client participant handler as Exception handler participant dep as Dep with yield participant operation as Path Operation participant tasks as Backgr...Exception and can change the response client ->> dep: Start request Note over dep: Run code up to yield opt raise dep -->> handler: Raise HTTPException handler -->> client: HTTP error response dep -->> dep: Raise other exception end dep ->> operation: R...un dependency, e.g. DB session opt raise operation -->> handler: Raise HTTPException handler -->> client: HTTP error response operation -->> dep: Raise other exception end operation ->>... - https://man.mtool.work/fastapi/0.115/tutorial/dependencies/dependencies-with-yie...
- Lifespan Events 8042
- 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
...e and then see how to solve it with this. Let's imagine that you have some machine learning models that you want to use to handle requests. ? The same models are shared among requests, so, it's not one model per request, or one per user or something sim...lifespan parameter of the FastAPI app as described above. If you provide a lifespan parameter, startup and shutdown event handlers will no longer be called. It's all lifespan or all events, not both. You can probably skip this part. There's an alternat...ive way to define this logic to be executed during startup and during shutdown . You can define event handlers (functions) that need to be executed before the application starts up, or when the application is shutting down. These fu... - https://man.mtool.work/fastapi/0.115/advanced/events/
- FastAPI class 7896
- FastAPI class Here's the reference information for the FastAPI class, with all its parameters, attributes and methods. You can import the FastAPI class directly from fastapi : from fastapi import FastAPI ::: fastapi.FastAPI options: members
...ebsocket - include_router - get - put - post - delete - options - head - patch - trace - on_event - middleware - exception_handler... - https://man.mtool.work/fastapi/0.115/reference/fastapi/
- Release Notes 7659
- 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
...tom GitHub Action. PR #13270 by @tiangolo . ? Update FastAPI People Experts script, refactor and optimize data fetching to handle rate limits. PR #13267 by @tiangolo . ⬆ Bump pypa/gh-action-pypi-publish from 1.12.3 to 1.12.4. PR #13251 by @dependabot[bo...er yield was not possible, the exit code in dependencies with yield was executed after the response was sent, so Exception Handlers would have already run. This was designed this way mainly to allow using the same objects "yielded" by dependencies insid...nd each column is one of the parts interacting or executing code. sequenceDiagram participant client as Client participant handler as Exception handler participant dep as Dep with yield participant operation as Path Operation participant tasks as Backgr... - https://man.mtool.work/fastapi/0.115/release-notes/
PREV
1
NEXT