Explore
Sign In
skills/fastapi__fastapi
1
0
Fork 0
You've already forked fastapi__fastapi
mirror of https://github.com/fastapi/fastapi.git synced 2026-09-14 13:36:21 +08:00
Code Issues Packages Projects Releases Wiki Activity
Files
02e108d1663149faac4156dd23595cbdf74287c2
fastapi__fastapi/docs_src/handling_errors/tutorial002.py
T

17 lines
404 B
Python
Raw Normal View History

:sparkles: Add HTTPException with custom headers (#35) * :memo: Update Release Notes with issue templates * :sparkles: Add HTTPException with support for headers Including docs and tests * :memo: Update Security docs to use new HTTPException
2019-02-16 17:01:29 +04:00
from fastapi import FastAPI, HTTPException
app = FastAPI()
items = {"foo": "The Foo Wrestlers"}
@app.get("/items-header/{item_id}")
:art: Improve automatic naming of path operations in API docs (#155) * :art: Improve operation summary naming * :memo: Update names in README * :truck: Improve names of security tutorial
2019-04-12 21:25:26 +04:00
async def read_item_header(item_id: str):
:sparkles: Add HTTPException with custom headers (#35) * :memo: Update Release Notes with issue templates * :sparkles: Add HTTPException with support for headers Including docs and tests * :memo: Update Security docs to use new HTTPException
2019-02-16 17:01:29 +04:00
if item_id not in items:
raise HTTPException(
status_code=404,
detail="Item not found",
headers={"X-Error": "There goes my error"},
)
return {"item": items[item_id]}
Reference in New Issue Copy Permalink
Version: v1.25.5 Page: 506ms Template: 4ms
Auto
English
Bahasa Indonesia Deutsch English Español Français Gaeilge Italiano Latviešu Magyar nyelv Nederlands Polski Português de Portugal Português do Brasil Suomi Svenska Türkçe Čeština Ελληνικά Български Русский Українська فارسی മലയാളം 日本語 简体中文 繁體中文(台灣) 繁體中文(香港) 한국어