-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CRUD Endpoint POST response is a list #211
Comments
Also it returns 201 instead of 200 as in the OpenAPI schema (for FastAPIWrapper), the schema should be fixed or if it can't, change to 200 |
@mastercoms I think |
I think what's going on is we're returning a piccolo_api/piccolo_api/fastapi/endpoints.py Line 393 in 40d4316
|
@dantownsend I don't think we should change anything because both |
@sinisaos Sorry, I wasn't clear - they both return 201, but in the Swagger docs it probably say 200. It's because we don't tell FastAPI what status code we're returning. |
@dantownsend Aha, now I understand! Here we can add Should we do it for all methods? |
@sinisaos yeah, at least for any which don't return 200 |
@dantownsend If you OK with this changes fastapi_app.add_api_route(
path=root_url,
endpoint=post,
response_model=self.ModelOut,
status_code=status.HTTP_201_CREATED, # new line
methods=["POST"],
**fastapi_kwargs.get_kwargs("post"),
) I can try to do this tomorrow for all the methods to have the same status codes in the Swagger docs as in the |
@sinisaos Yes, that looks right. |
On making a POST request to a CRUD endpoint, the response is something like:
IMHO this should be a dict following good REST practices and not a list since we cannot post multiple objects to the CRUD Endpoint. The client should be able to run something like:
The problem stems from this line: https://github.com/piccolo-orm/piccolo_api/blob/master/piccolo_api/crud/endpoints.py#L819
Actually
row.save().run()
seems to always return a list with one object ... assuming this is the case, we could strip the object out of the list and simply return the dict:The text was updated successfully, but these errors were encountered: