from fastapi import FastAPI, Response
from fastapi.responses import JSONResponse
from pydantic import BaseModel
app = FastAPI()
class User(BaseModel):
username: str
password: str
'''
响应头 Response
'''
# @app.post("/login")
# def login(response: Response):
# response.headers["x-jwt-token"] = "This is jwt-token"
# response.headers.append("x-token","This is token")
@app.post("/login")
def login(user: User):
response = JSONResponse(
{
"username": user.username,
"password": user.password
},
status_code=201,
headers={"x-jwt-token": "value"}
)
return response