我有一个使用Python FastAPI实现的服务器,我通过POST
请求获得了sending large data (~2 GB) to the server.一旦请求在服务器端被处理,我想向客户端返回一个201 "Created"
响应.
一个201
响应应该有一个主体,所以我不应该发送一个带有空主体的响应(https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST),但同时,I don't want to send back the newly created resource as it is so large,客户端不需要在POST
请求点的资源.或者,我会try 用204 "No Content"
来响应,但它似乎不是成功的POST
请求的推荐响应.
假设发送的响应为201
,则为what should be the body of the response to avoid large data sent back for no reason?
以下是描述我的问题的最小代码,当前返回201
响应,但正文为空:
from fastapi import FastAPI, HTTPException, Response, status
app = FastAPI()
@app.post("/data", status_code=status.HTTP_201_CREATED)
async def send_data(data, response: Response):
try:
# process data on the server
# ...
pass
except Exception as e:
raise HTTPException(status.HTTP_500_INTERNAL_SERVER_ERROR, e)
return response # response with empty body