Results of 1 - 10 of about 18 for Header (0.004 sec.)
- ヘッダーのパラメータ 11890
- ヘッダーのパラメータ ヘッダーのパラメータは、 Query や Path 、 Cookie のパラメータを定義するのと同じように定義できます。 Header をインポート まず、 Header をインポートします: Python 3.8+ - non-Annotated from typing import Union from fastapi
...import FastAPI , Header app = FastAPI () @app . get ( "/items/" ) async def read_items ( user_agent : Union [ str , None ] = Header ( default = No...thon 3.10+ Python 3.9+ Python 3.8+ Python 3.10+ - non-Annotated from typing import Annotated from fastapi import FastAPI , Header app = FastAPI () @app . get ( "/items/" ) async def read_items ( user_agent : Annotated [ str | None , Header ()] = None )...: return { "User-Agent" : user_agent } from typing import Annotated , Union from fastapi import FastAPI , Header app = FastAPI () @app . get ( "/items/" ) async def read_items ( user_agent : Annotated [ Union [ str , None ], Header ()]... - https://man.mtool.work/fastapi/0.115/tutorial/header-params/
- path operationデコレータの依存関係 11530
- path operationデコレータの依存関係 場合によっては path operation関数 の中で依存関係の戻り値を本当に必要としないこともあります。 もしくは、依存関係が値を返さない場合もあります。 しかし、それでも実行・解決する必要があります。 このような場合、
...受け取ります。 それは Depends() の list であるべきです: Python 3.8+ - non-Annotated from fastapi import Depends , FastAPI , Header , HTTPException app = FastAPI () async def verify_token ( x_token : str = Header ()): if x_token != "fake-super-secret-tok...en" : raise HTTPException ( status_code = 400 , detail = "X-Token header invalid" ) async def verify_key ( x_key : str = Header ()): if x_key != "fake-super-secret-key" : raise HTTPException ( st...atus_code = 400 , detail = "X-Key header invalid" ) return x_key @app . get ( "/items/" , dependencies = [ Depends ( verify_token ), Depends ( verify_key )]) async... - https://man.mtool.work/fastapi/0.115/tutorial/dependencies/dependencies-in-path-...
- Header Parameter Models 10964
- Header Parameter Models Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . If you have a group of related header parameters , you can create a Pydantic model to decla
...eclare validations and metadata for all the parameters at once. ? Note This is supported since FastAPI version 0.115.0 . ? Header Parameters with a Pydantic Model Declare the header parameters that you need in a Pydantic model , and then declare the pa...rameter as Header : Python 3.10+ from typing import Annotated from fastapi import FastAPI , Header from pydantic import BaseModel app = Fast...API () class CommonHeaders ( BaseModel ): host : str save_data : bool if_modified_since : str | None = None traceparent : str | None = None x_tag :... - https://man.mtool.work/fastapi/0.115/tutorial/header-param-models/
- Bigger Applications - Multiple Files 10500
- Bigger Applications - Multiple Files Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . If you are building an application or a web API, it's rarely the case that you
...hem in their own dependencies module ( app/dependencies.py ). We will now use a simple dependency to read a custom X-Token header: Python 3.9+ Python 3.8+ Python 3.8+ non-Annotated app/dependencies.py from typing import Annotated from fastapi import He...ader , HTTPException async def get_token_header ( x_token : Annotated [ str , Header ()]): if x_token != "fake-super-secret-token" : raise HTTPException ( status_code = 4...00 , detail = "X-Token header invalid" ) async def get_query_token ( token : str ): if token != "jessica" : raise HTTPException ( status_code = 400 , de... - https://man.mtool.work/fastapi/0.115/tutorial/bigger-applications/
- Global Dependencies 10415
- Global Dependencies Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . For some types of applications you might want to add dependencies to the whole application. Sim
...e, they will be applied to all the path operations in the application: Python 3.9+ from fastapi import Depends , FastAPI , Header , HTTPException from typing_extensions import Annotated async def verify_token ( x_token : Annotated [ str , Header ()]):...if x_token != "fake-super-secret-token" : raise HTTPException ( status_code = 400 , detail = "X-Token header invalid" ) async def verify_key ( x_key : Annotated [ str , Header ()]): if x_key != "fake-super-secret-key" : raise HTTPE...xception ( status_code = 400 , detail = "X-Key header invalid" ) return x_key app = FastAPI ( dependencies = [ Depends ( verify_token ), Depends ( verify_key )]) @app . get ( "... - https://man.mtool.work/fastapi/0.115/tutorial/dependencies/global-dependencies/
- テスト 10140
- テスト Starlette のおかげで、 FastAPI アプリケーションのテストは簡単で楽しいものになっています。 HTTPX がベースなので、非常に使いやすく直感的です。 これを使用すると、 FastAPI と共に pytest を直接利用できます。 TestClient を使用 TestClient を
...ます。 これらの path operation には X-Token ヘッダーが必要です。 Python 3.10+ - non-Annotated from fastapi import FastAPI , Header , HTTPException from pydantic import BaseModel fake_secret_token = "coneofsilence" fake_db = { "foo" : { "id" : "foo" , "t...e = None @app . get ( "/items/ {item_id} " , response_model = Item ) async def read_main ( item_id : str , x_token : str = Header ()): if x_token != fake_secret_token : raise HTTPException ( status_code = 400 , detail = "Invalid X-Token header" ) if it...ake_db [ item_id ] @app . post ( "/items/" , response_model = Item ) async def create_item ( item : Item , x_token : str = Header ()): if x_token != fake_secret_token : raise HTTPException ( status_code = 400 , detail = "Invalid X-Token header" ) if it... - https://man.mtool.work/fastapi/0.115/tutorial/testing/
- Request Parameters 8304
- 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
...ncludes: Query() Path() Body() Cookie() Header() Form() File() You can import them all directly from fastapi : from fastapi import Body , Cookie , File , Form , Header ,...Path , Query ::: fastapi.Query ::: fastapi.Path ::: fastapi.Body ::: fastapi.Cookie ::: fastapi.Header ::: fastapi.Form ::: fastapi.File... - https://man.mtool.work/fastapi/0.115/reference/parameters/
- Release Notes 7824
- 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
...DanielYang59 . ? Fix test badge. PR #13313 by @esadek . Translations ? Add Ukrainian translation for docs/uk/docs/tutorial/header-params.md . PR #13381 by @valentinDruzhinin . ? Add Ukrainian translation for docs/uk/docs/tutorial/request-files.md . PR...PR #13181 by @alejsdev . ✅ Simplify tests for path_operation_configurations. PR #13180 by @alejsdev . ✅ Simplify tests for header_params. PR #13179 by @alejsdev . ✅ Simplify tests for extra_models. PR #13178 by @alejsdev . ✅ Simplify tests for extra_da...s/tutorial/query-params-str-validations.md . PR #12928 by @Vincy1230 . ? Add Chinese translation for docs/zh/docs/tutorial/header-param-models.md . PR #13040 by @Zhongheng-Cheng . ? Update Chinese translation for docs/zh/docs/tutorial/path-params.md .... - https://man.mtool.work/fastapi/0.115/release-notes/
- Advanced Middleware 7635
- Advanced Middleware Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . In the main tutorial you read how to add Custom Middleware to your application. And then you al
...: return { "message" : "Hello World" } TrustedHostMiddleware Enforces that all incoming requests have a correctly set Host header, in order to guard against HTTP Host Header attacks. Python 3.8+ from fastapi import FastAPI from fastapi.middleware.trust...0 response will be sent. GZipMiddleware Handles GZip responses for any request that includes "gzip" in the Accept-Encoding header. The middleware will handle both standard and streaming responses. Python 3.8+ from fastapi import FastAPI from fastapi.mi...r compression but smaller file sizes. Other middlewares There are many other ASGI middlewares. For example: Uvicorn's ProxyHeadersMiddleware MessagePack To see other available middlewares check Starlette's Middleware docs and the ASGI Awesome List .... - https://man.mtool.work/fastapi/0.115/advanced/middleware/
- HTTP Basic Auth 7463
- HTTP Basic Auth Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . For the simplest cases, you can use HTTP Basic Auth. In HTTP Basic Auth, the application expects a
...t contains a username and a password. If it doesn't receive it, it returns an HTTP 401 "Unauthorized" error. And returns a header WWW-Authenticate with a value of Basic , and an optional realm parameter. That tells the browser to show the integrated pr...ompt for a username and password. Then, when you type that username and password, the browser sends them in the header automatically. Simple HTTP Basic Auth Import HTTPBasic and HTTPBasicCredentials . Create a " security scheme" using HTTPBa...ssword ): raise HTTPException ( status_code = status . HTTP_401_UNAUTHORIZED , detail = "Incorrect username or password" , headers = { "WWW-Authenticate" : "Basic" }, ) return credentials . username @app . get ( "/users/me" ) def read_current_user ( us... - https://man.mtool.work/fastapi/0.115/advanced/security/http-basic-auth/