mirror of
https://github.com/fastapi/fastapi.git
synced 2026-01-06 04:57:58 -05:00
* ✨ Add support for declaring a Response parameter to set headers and cookies * ✅ Add source for docs and tests * 📝 Add docs for setting headers, cookies and status code * 📝 Add attribution to Hug for inspiring response parameters
16 lines
453 B
Python
16 lines
453 B
Python
from fastapi import FastAPI
|
|
from starlette.responses import Response
|
|
from starlette.status import HTTP_201_CREATED
|
|
|
|
app = FastAPI()
|
|
|
|
tasks = {"foo": "Listen to the Bar Fighters"}
|
|
|
|
|
|
@app.put("/get-or-create-task/{task_id}", status_code=200)
|
|
def get_or_create_task(task_id: str, response: Response):
|
|
if task_id not in tasks:
|
|
tasks[task_id] = "This didn't exist before"
|
|
response.status_code = HTTP_201_CREATED
|
|
return tasks[task_id]
|