コンテンツにスキップ
per page, with , order by , clip by
Results of 1 - 10 of about 19 for responses (0.002 sec.)
Additional Responses in OpenAPI 12755
Additional Responses in OpenAPI Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . Warning This is a rather advanced topic. If you are starting with FastAPI , you mig ... ht not need this. You can declare additional responses, with additional status codes, media types, descriptions, etc. Those additional responses will be included in the OpenAPI ... schema, so they will also appear in the API docs. But for those additional responses you have to make sure you return a Response like JSONResponse directly, with your status code and content. Additional Resp ... onse with model You can pass to your path operation decorators a parameter responses . It receives a dict : the keys are status codes for each response (like 200 ), and the values are other dict s with the i ...
https://man.mtool.work/fastapi/0.115/advanced/additional-responses/
Custom Response Classes - File, HTML, Redirect, Streaming, etc. 12379
Custom Response Classes - File, HTML, Redirect, Streaming, etc. There are several custom response classes you can use to create an instance and return them directly from your path operations . Read more about it in the FastAPI docs for Cust ... om Response - HTML, Stream, File, others . You can import them directly from fastapi.responses : from fastapi.responses import ( FileResponse , HTMLResponse , JSONResponse , ORJSONResponse , PlainTextResponse , Redire ... ctResponse , Response , StreamingResponse , UJSONResponse , ) FastAPI Responses There are a couple of custom FastAPI response classes, you can use them to optimize JSON performance. ::: fastapi.response ... - media_type - body - background - raw_headers - render - init_headers - headers - set_cookie - delete_cookie ::: fastapi.responses.ORJSONResponse options: members: - charset - status_code - media_type - body - background - raw_headers - render - init_he ...
https://man.mtool.work/fastapi/0.115/reference/responses/
Bigger Applications - Multiple Files 9903
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 ... ame } You can think of APIRouter as a "mini FastAPI " class. All the same options are supported. All the same parameters , responses , dependencies , tags , etc. Tip In this example, the variable is called router , but you can name it however you want. We ... We know all the path operations in this module have the same: Path prefix : /items . tags : (just one tag: items ). Extra responses . dependencies : they all need that X-Token dependency we created. So, instead of adding all that to each path operation , ... _token_header router = APIRouter ( prefix = "/items" , tags = [ "items" ], dependencies = [ Depends ( get_token_header )], responses = { 404 : { "description" : "Not found" }}, ) fake_items_db = { "plumbus" : { "name" : "Plumbus" }, "gun" : { "name" : "Po ...
https://man.mtool.work/fastapi/0.115/tutorial/bigger-applications/
カスタムレスポンス - HTML、ストリーム、ファイル、その他のレスポンス 9681
カスタムレスポンス - HTML、ストリーム、ファイル、その他のレスポンス デフォルトでは、 FastAPI は JSONResponse を使ってレスポンスを返します。 レスポンスを直接返す で見たように、 Response を直接返すことでこの挙動をオーバーライドできます。 しか ... (サブクラス) をインポートし、 path operationデコレータ に宣言します。 Python 3.8+ from fastapi import FastAPI from fastapi.responses import ORJSONResponse app = FastAPI () @app . get ( "/items/" , response_class = ORJSONResponse ) async def read_items (): ... る。 path operation のパラメータ content_type に HTMLResponse を渡す。 Python 3.8+ from fastapi import FastAPI from fastapi.responses import HTMLResponse app = FastAPI () @app . get ( "/items/" , response_class = HTMLResponse ) async def read_items (): ret ... す。 上記と同じ例において、 HTMLResponse を返すと、このようになります: Python 3.8+ from fastapi import FastAPI from fastapi.responses import HTMLResponse app = FastAPI () @app . get ( "/items/" ) async def read_items (): html_content = """ <html> <head> <t ...
https://man.mtool.work/fastapi/0.115/advanced/custom-response/
Response Headers 9323
Response Headers Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . Use a Response parameter You can declare a parameter of type Response in your path operation funct ... a Response Directly and pass the headers as an additional parameter: Python 3.8+ from fastapi import FastAPI from fastapi.responses import JSONResponse app = FastAPI () @app . get ( "/headers/" ) def get_headers (): content = { "message" : "Hello World" ... en-US" } return JSONResponse ( content = content , headers = headers ) Technical Details You could also use from starlette.responses import Response or from starlette.responses import JSONResponse . FastAPI provides the same starlette.responses as fastapi ... .responses just as a convenience for you, the developer. But most of the available responses come directly from Starlette. And as the ...
https://man.mtool.work/fastapi/0.115/advanced/response-headers/
Response Cookies 9271
Response Cookies Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . Use a Response parameter You can declare a parameter of type Response in your path operation funct ... urn a Response Directly . Then set Cookies in it, and then return it: Python 3.8+ from fastapi import FastAPI from fastapi.responses import JSONResponse app = FastAPI () @app . post ( "/cookie/" ) def create_cookie (): content = { "message" : "Come to the ... ny data that should have been filtered by a response_model . More info Technical Details You could also use from starlette.responses import Response or from starlette.responses import JSONResponse . FastAPI provides the same starlette.responses as fastapi ... .responses just as a convenience for you, the developer. But most of the available responses come directly from Starlette. And as the ...
https://man.mtool.work/fastapi/0.115/advanced/response-cookies/
追加のステータスコード 9049
追加のステータスコード デフォルトでは、 FastAPI は JSONResponse を使ってレスポンスを返します。その JSONResponse の中には、 path operation が返した内容が入ります。 それは、デフォルトのステータスコードか、 path operation でセットしたものを利用 ... 容を返します。 Python 3.8+ - non-Annotated from typing import Union from fastapi import Body , FastAPI , status from fastapi.responses import JSONResponse app = FastAPI () items = { "foo" : { "name" : "Fighters" , "size" : 6 }, "bar" : { "name" : "Tenders" ... on 3.8+ Python 3.10+ - non-Annotated from typing import Annotated from fastapi import Body , FastAPI , status from fastapi.responses import JSONResponse app = FastAPI () items = { "foo" : { "name" : "Fighters" , "size" : 6 }, "bar" : { "name" : "Tenders" ... 1_CREATED , content = item ) from typing import Annotated , Union from fastapi import Body , FastAPI , status from fastapi.responses import JSONResponse app = FastAPI () items = { "foo" : { "name" : "Fighters" , "size" : 6 }, "bar" : { "name" : "Tenders" ...
https://man.mtool.work/fastapi/0.115/advanced/additional-status-codes/
Request Files 8554
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 ... ytes or UploadFile : Python 3.9+ from typing import Annotated from fastapi import FastAPI , File , UploadFile from fastapi.responses import HTMLResponse app = FastAPI () @app . post ( "/files/" ) async def create_files ( files : Annotated [ list [ bytes ] ... Annotated Python 3.8+ - non-Annotated from typing import List from fastapi import FastAPI , File , UploadFile from fastapi.responses import HTMLResponse from typing_extensions import Annotated app = FastAPI () @app . post ( "/files/" ) async def create_fi ... ontent ) Tip Prefer to use the Annotated version if possible. from fastapi import FastAPI , File , UploadFile from fastapi.responses import HTMLResponse app = FastAPI () @app . post ( "/files/" ) async def create_files ( files : list [ bytes ] = File ()): ...
https://man.mtool.work/fastapi/0.115/tutorial/request-files/
エラーハンドリング 8315
エラーハンドリング 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 = Fas ... s! yolo did something. There goes a rainbow..." } 技術詳細 また、 from starlette.requests import Request と from starlette.responses import JSONResponse を使用することもできます。 FastAPI は開発者の利便性を考慮して、 fastapi.responses と同じ starlette.res ... Python 3.8+ from fastapi import FastAPI , HTTPException from fastapi.exceptions import RequestValidationError from fastapi.responses import PlainTextResponse from starlette.exceptions import HTTPException as StarletteHTTPException app = FastAPI () @app . ...
https://man.mtool.work/fastapi/0.115/tutorial/handling-errors/
レスポンスを直接返す 8179
レスポンスを直接返す FastAPI の path operation では、通常は任意のデータを返すことができます: 例えば、 dict 、 list 、Pydanticモデル、データベースモデルなどです。 デフォルトでは、 FastAPI は JSON互換エンコーダ で説明されている jsonable_encod ... t datetime from typing import Union from fastapi import FastAPI from fastapi.encoders import jsonable_encoder from fastapi.responses import JSONResponse from pydantic import BaseModel class Item ( BaseModel ): title : str timestamp : datetime description ... ata = jsonable_encoder ( item ) return JSONResponse ( content = json_compatible_item_data ) 技術詳細 また、 from starlette.responses import JSONResponse も利用できます。 FastAPI は開発者の利便性のために fastapi.responses という starlette.responses と同じも ... 備考 Response を直接返す場合、バリデーションや、変換 (シリアライズ) や、自動ドキュメントは行われません。 しかし、 Additional Responses in OpenAPI に記載されたようにドキュメントを書くこともできます。 後のセクションで、カスタム Response を使用・宣言しながら、 ...
https://man.mtool.work/fastapi/0.115/advanced/response-directly/
PREV 1 2 NEXT