Add HTTPException with custom headers (#35)

* 📝 Update Release Notes with issue templates

*  Add HTTPException with support for headers

Including docs and tests

* 📝 Update Security docs to use new HTTPException
This commit is contained in:
Sebastián Ramírez
2019-02-16 17:01:29 +04:00
committed by GitHub
parent 7edbd9345b
commit 8772e2f2ee
16 changed files with 452 additions and 14 deletions

View File

@@ -0,0 +1,16 @@
from fastapi import FastAPI, HTTPException
app = FastAPI()
items = {"foo": "The Foo Wrestlers"}
@app.get("/items-header/{item_id}")
async def create_item_header(item_id: str):
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]}