Results of 1 - 10 of about 33 for post (0.009 sec.)
- Request Files 14150
- Request Files Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . You can define files to be uploaded by the client using File . Info To receive uploaded files, first
...fastapi : Python 3.9+ from typing import Annotated from fastapi import FastAPI , File , UploadFile app = FastAPI () @app . post ( "/files/" ) async def create_file ( file : Annotated [ bytes , File ()]): return { "file_size" : len ( file )} @app . po...-Annotated from fastapi import FastAPI , File , UploadFile from typing_extensions import Annotated app = FastAPI () @app . post ( "/files/" ) async def create_file ( file : Annotated [ bytes , File ()]): return { "file_size" : len ( file )} @app . po...p Prefer to use the Annotated version if possible. from fastapi import FastAPI , File , UploadFile app = FastAPI () @app . post ( "/files/" ) async def create_file ( file : bytes = File ()): return { "file_size" : len ( file )} @app . post ( "/upload... - https://man.mtool.work/fastapi/0.115/tutorial/request-files/
- SQL (Relational) Databases 10700
- SQL (Relational) Databases Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . FastAPI doesn't require you to use a SQL (relational) database. But you can use any data
...n SQLAlchemy, you can easily use any database supported by SQLAlchemy (which makes them also supported by SQLModel), like: PostgreSQL MySQL SQLite Oracle Microsoft SQL Server, etc. In this example, we'll use SQLite , because it uses a single file and...n copy this example and run it as is. Later, for your production application, you might want to use a database server like PostgreSQL . Tip There is an official project generator with FastAPI and PostgreSQL including a frontend and more tools: https:...Depends ( get_session )] app = FastAPI () @app . on_event ( "startup" ) def on_startup (): create_db_and_tables () @app . post ( "/heroes/" ) def create_hero ( hero : Hero , session : SessionDep ) -> Hero : session . add ( hero ) session . commit ()... - https://man.mtool.work/fastapi/0.115/tutorial/sql-databases/
- OpenAPI Callbacks 9930
- 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
...(optional), 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 mone...y. 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 Fas...ol class InvoiceEventReceived ( BaseModel ): ok : bool invoices_callback_router = APIRouter () @invoices_callback_router . post ( "{$callback_url}/invoices/{$request.body.id}" , response_model = InvoiceEventReceived ) def invoice_notification ( body... - https://man.mtool.work/fastapi/0.115/advanced/openapi-callbacks/
- テスト 9674
- テスト Starlette のおかげで、 FastAPI アプリケーションのテストは簡単で楽しいものになっています。 HTTPX がベースなので、非常に使いやすく直感的です。 これを使用すると、 FastAPI と共に pytest を直接利用できます。 TestClient を使用 TestClient を
...します。 そのファイルには、エラーを返す可能性のある GET オペレーションがあります。 また、いくつかのエラーを返す可能性のある POST オペレーションもあります。 これらの path operation には X-Token ヘッダーが必要です。 Python 3.10+ - non-Annotated from fas...d not in fake_db : raise HTTPException ( status_code = 404 , detail = "Item not found" ) return fake_db [ item_id ] @app . post ( "/items/" , response_model = Item ) async def create_item ( item : Item , x_token : str = Header ()): if x_token != fake...d not in fake_db : raise HTTPException ( status_code = 404 , detail = "Item not found" ) return fake_db [ item_id ] @app . post ( "/items/" , response_model = Item ) async def create_item ( item : Item , x_token : Annotated [ str , Header ()]): if x_... - https://man.mtool.work/fastapi/0.115/tutorial/testing/
- Separate OpenAPI Schemas for Input and Output or Not 9625
- Separate OpenAPI Schemas for Input and Output or Not Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . When using Pydantic v2 , the generated OpenAPI is a bit more e
...rom pydantic import BaseModel class Item ( BaseModel ): name : str description : str | None = None app = FastAPI () @app . post ( "/items/" ) def create_item ( item : Item ): return item @app . get ( "/items/" ) def read_items () -> list [ Item ]: re...dantic import BaseModel class Item ( BaseModel ): name : str description : Optional [ str ] = None app = FastAPI () @app . post ( "/items/" ) def create_item ( item : Item ): return item @app . get ( "/items/" ) def read_items () -> list [ Item ]: re...ic import BaseModel class Item ( BaseModel ): name : str description : Union [ str , None ] = None app = FastAPI () @app . post ( "/items/" ) def create_item ( item : Item ): return item @app . get ( "/items/" ) def read_items () -> List [ Item ]: re... - https://man.mtool.work/fastapi/0.115/how-to/separate-openapi-schemas/
- Path Operationの設定 9577
- Path Operationの設定 path operationデコレータ を設定するためのパラメータがいくつかあります。 注意 これらのパラメータは path operation関数 ではなく、 path operationデコレータ に直接渡されることに注意してください。 レスポンスステータスコード
...ription : Union [ str , None ] = None price : float tax : Union [ float , None ] = None tags : Set [ str ] = set () @app . post ( "/items/" , response_model = Item , status_code = status . HTTP_201_CREATED ) async def create_item ( item : Item ): ret...l ): name : str description : str | None = None price : float tax : float | None = None tags : set [ str ] = set () @app . post ( "/items/" , response_model = Item , status_code = status . HTTP_201_CREATED ) async def create_item ( item : Item ): ret...ription : Union [ str , None ] = None price : float tax : Union [ float , None ] = None tags : set [ str ] = set () @app . post ( "/items/" , response_model = Item , status_code = status . HTTP_201_CREATED ) async def create_item ( item : Item ): ret... - https://man.mtool.work/fastapi/0.115/tutorial/path-operation-configuration/
- Form Models 8759
- Form Models Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . You can use Pydantic models to declare form fields in FastAPI. Info To use forms, first install python-
..., Form from pydantic import BaseModel app = FastAPI () class FormData ( BaseModel ): username : str password : str @app . post ( "/login/" ) async def login ( data : Annotated [ FormData , Form ()]): return data ? Other versions and variants Python...rom typing_extensions import Annotated app = FastAPI () class FormData ( BaseModel ): username : str password : str @app . post ( "/login/" ) async def login ( data : Annotated [ FormData , Form ()]): return data Tip Prefer to use the Annotated versi..., Form from pydantic import BaseModel app = FastAPI () class FormData ( BaseModel ): username : str password : str @app . post ( "/login/" ) async def login ( data : FormData = Form ()): return data FastAPI will extract the data for each field from... - https://man.mtool.work/fastapi/0.115/tutorial/request-form-models/
- フォームデータ 8647
- フォームデータ JSONの代わりにフィールドを受け取る場合は、 Form を使用します。 情報 フォームを使うためには、まず python-multipart をインストールします。 たとえば、 pip install python-multipart のように。 Form のインポート fastapi から Form を
...インポートします: Python 3.8+ - non-Annotated from fastapi import FastAPI , Form app = FastAPI () @app . post ( "/login/" ) async def login ( username : str = Form (), password : str = Form ()): return { "username" : username } ? Ot...d variants Python 3.9+ Python 3.8+ from typing import Annotated from fastapi import FastAPI , Form app = FastAPI () @app . post ( "/login/" ) async def login ( username : Annotated [ str , Form ()], password : Annotated [ str , Form ()]): return { "u...sername" : username } from fastapi import FastAPI , Form from typing_extensions import Annotated app = FastAPI () @app . post ( "/login/" ) async def login ( username : Annotated [ str , Form ()], password : Annotated [ str , Form ()]): return { "u... - https://man.mtool.work/fastapi/0.115/tutorial/request-forms/
- レスポンスモデル 8599
- レスポンスモデル path operations のいずれにおいても、 response_model パラメータを使用して、レスポンスのモデルを宣言することができます: @app.get() @app.post() @app.put() @app.delete() など。 Python 3.8+ from typing import Any , List , Union
...escription : Union [ str , None ] = None price : float tax : Union [ float , None ] = None tags : List [ str ] = [] @app . post ( "/items/" , response_model = Item ) async def create_item ( item : Item ) -> Any : return item @app . get ( "/items/" ,...odel ): name : str description : str | None = None price : float tax : float | None = None tags : list [ str ] = [] @app . post ( "/items/" , response_model = Item ) async def create_item ( item : Item ) -> Any : return item @app . get ( "/items/" ,...escription : Union [ str , None ] = None price : float tax : Union [ float , None ] = None tags : list [ str ] = [] @app . post ( "/items/" , response_model = Item ) async def create_item ( item : Item ) -> Any : return item @app . get ( "/items/" ,... - https://man.mtool.work/fastapi/0.115/tutorial/response-model/
- Simple OAuth2 with Password and Bearer 8599
- Simple OAuth2 with Password and Bearer Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . Now let's build from the previous chapter and add the missing parts to have
...current_user . disabled : raise HTTPException ( status_code = 400 , detail = "Inactive user" ) return current_user @app . post ( "/token" ) async def login ( form_data : Annotated [ OAuth2PasswordRequestForm , Depends ()]): user_dict = fake_users_db...current_user . disabled : raise HTTPException ( status_code = 400 , detail = "Inactive user" ) return current_user @app . post ( "/token" ) async def login ( form_data : Annotated [ OAuth2PasswordRequestForm , Depends ()]): user_dict = fake_users_db...current_user . disabled : raise HTTPException ( status_code = 400 , detail = "Inactive user" ) return current_user @app . post ( "/token" ) async def login ( form_data : Annotated [ OAuth2PasswordRequestForm , Depends ()]): user_dict = fake_users_db... - https://man.mtool.work/fastapi/0.115/tutorial/security/simple-oauth2/