Search Options

Display Count
Sort
Preferred Language
Advanced Search

Results 1 - 10 of 50 for APIRoute (0.06 seconds)

  1. docs/en/docs/how-to/custom-request-and-route.md

    # Custom Request and APIRoute class { #custom-request-and-apiroute-class }
    
    In some cases, you may want to override the logic used by the `Request` and `APIRoute` classes.
    
    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.
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Thu Mar 05 18:13:19 GMT 2026
    - 4.4K bytes
    - Click Count (0)
  2. docs/zh-hant/docs/how-to/custom-request-and-route.md

    # 自訂 Request 與 APIRoute 類別 { #custom-request-and-apiroute-class }
    
    在某些情況下,你可能想要覆寫 `Request` 與 `APIRoute` 類別所使用的邏輯。
    
    特別是,這可能是替代中介軟體(middleware)中實作邏輯的一個好方法。
    
    例如,如果你想在應用程式處理之前讀取或操作請求本文(request body)。
    
    /// danger
    
    這是進階功能。
    
    如果你剛開始使用 **FastAPI**,可以先跳過本節。
    
    ///
    
    ## 使用情境 { #use-cases }
    
    可能的使用情境包括:
    
    * 將非 JSON 的請求本文轉換為 JSON(例如 [`msgpack`](https://msgpack.org/index.html))。
    * 解壓縮以 gzip 壓縮的請求本文。
    * 自動記錄所有請求本文。
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Fri Mar 20 17:05:38 GMT 2026
    - 4.2K bytes
    - Click Count (0)
  3. docs/ko/docs/how-to/custom-request-and-route.md

    # 커스텀 Request 및 APIRoute 클래스 { #custom-request-and-apiroute-class }
    
    일부 경우에는 `Request`와 `APIRoute` 클래스에서 사용되는 로직을 오버라이드하고 싶을 수 있습니다.
    
    특히, 이는 middleware에 있는 로직의 좋은 대안이 될 수 있습니다.
    
    예를 들어, 애플리케이션에서 처리되기 전에 요청 바디를 읽거나 조작하고 싶을 때가 그렇습니다.
    
    /// danger | 위험
    
    이 기능은 "고급" 기능입니다.
    
    **FastAPI**를 이제 막 시작했다면 이 섹션은 건너뛰는 것이 좋습니다.
    
    ///
    
    ## 사용 사례 { #use-cases }
    
    사용 사례에는 다음이 포함됩니다:
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Fri Mar 20 14:06:26 GMT 2026
    - 5.2K bytes
    - Click Count (0)
  4. docs_src/custom_request_and_route/tutorial002_py310.py

    from collections.abc import Callable
    
    from fastapi import Body, FastAPI, HTTPException, Request, Response
    from fastapi.exceptions import RequestValidationError
    from fastapi.routing import APIRoute
    
    
    class ValidationErrorLoggingRoute(APIRoute):
        def get_route_handler(self) -> Callable:
            original_route_handler = super().get_route_handler()
    
            async def custom_route_handler(request: Request) -> Response:
                try:
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Wed Dec 10 08:55:32 GMT 2025
    - 935 bytes
    - Click Count (0)
  5. docs_src/custom_request_and_route/tutorial003_py310.py

    import time
    from collections.abc import Callable
    
    from fastapi import APIRouter, FastAPI, Request, Response
    from fastapi.routing import APIRoute
    
    
    class TimedRoute(APIRoute):
        def get_route_handler(self) -> Callable:
            original_route_handler = super().get_route_handler()
    
            async def custom_route_handler(request: Request) -> Response:
                before = time.time()
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Wed Dec 10 08:55:32 GMT 2025
    - 1K bytes
    - Click Count (0)
  6. docs_src/path_operation_advanced_configuration/tutorial002_py310.py

    from fastapi import FastAPI
    from fastapi.routing import APIRoute
    
    app = FastAPI()
    
    
    @app.get("/items/")
    async def read_items():
        return [{"item_id": "Foo"}]
    
    
    def use_route_names_as_operation_ids(app: FastAPI) -> None:
        """
        Simplify operation IDs so that generated API clients have simpler function
        names.
    
        Should be called only after all routes have been added.
        """
        for route in app.routes:
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Thu Feb 12 13:19:43 GMT 2026
    - 572 bytes
    - Click Count (0)
  7. docs_src/custom_request_and_route/tutorial001_py310.py

    from fastapi.routing import APIRoute
    
    
    class GzipRequest(Request):
        async def body(self) -> bytes:
            if not hasattr(self, "_body"):
                body = await super().body()
                if "gzip" in self.headers.getlist("Content-Encoding"):
                    body = gzip.decompress(body)
                self._body = body
            return self._body
    
    
    class GzipRoute(APIRoute):
        def get_route_handler(self) -> Callable:
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Wed Dec 10 08:55:32 GMT 2025
    - 976 bytes
    - Click Count (0)
  8. tests/test_custom_route_class.py

    import pytest
    from fastapi import APIRouter, FastAPI
    from fastapi.routing import APIRoute
    from fastapi.testclient import TestClient
    from inline_snapshot import snapshot
    from starlette.routing import Route
    
    app = FastAPI()
    
    
    class APIRouteA(APIRoute):
        x_type = "A"
    
    
    class APIRouteB(APIRoute):
        x_type = "B"
    
    
    class APIRouteC(APIRoute):
        x_type = "C"
    
    
    router_a = APIRouter(route_class=APIRouteA)
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Sun Feb 08 10:18:38 GMT 2026
    - 3.3K bytes
    - Click Count (0)
  9. docs_src/custom_request_and_route/tutorial001_an_py310.py

    from fastapi.routing import APIRoute
    
    
    class GzipRequest(Request):
        async def body(self) -> bytes:
            if not hasattr(self, "_body"):
                body = await super().body()
                if "gzip" in self.headers.getlist("Content-Encoding"):
                    body = gzip.decompress(body)
                self._body = body
            return self._body
    
    
    class GzipRoute(APIRoute):
        def get_route_handler(self) -> Callable:
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Wed Dec 10 08:55:32 GMT 2025
    - 1015 bytes
    - Click Count (0)
  10. docs/ja/docs/how-to/custom-request-and-route.md

    # カスタム Request と APIRoute クラス { #custom-request-and-apiroute-class }
    
    場合によっては、`Request` や `APIRoute` クラスで使われるロジックを上書きしたいことがあります。
    
    特に、ミドルウェアでのロジックの代替として有効な場合があります。
    
    たとえば、アプリケーションで処理される前にリクエストボディを読み取ったり操作したりしたい場合です。
    
    /// danger | 警告
    
    これは「上級」機能です。
    
    FastAPI を始めたばかりの場合は、このセクションは読み飛ばしてもよいでしょう。
    
    ///
    
    ## ユースケース { #use-cases }
    
    ユースケースの例:
    
    * JSON ではないリクエストボディを JSON に変換する(例: [`msgpack`](https://msgpack.org/index.html))。
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Fri Mar 20 14:07:17 GMT 2026
    - 5.4K bytes
    - Click Count (0)
Back to Top