You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On making a POST request to a CRUD endpoint, the response is something like:
[{'id': 4}]
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:
>>> response = requests.post(crud_endpoint_url, json=data).json()
>>> response['id']
# created object id
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:
@mastercoms I think HTTP 201 CREATED is a good response status code because the request was successful and led to the creation of a new resource. Sorry if I'm wrong.
I think what's going on is we're returning a 201 from PiccoloCRUD, but FastAPIWrapper has the default of 200. They should be consistent really - it should be a quick fix.
@dantownsend I don't think we should change anything because both PiccoloCRUD and FastAPIWrapper ,in my case, return correct 201 on POST request? Sorry if I don't understand correctly.
Activity
mastercoms commentedon Apr 25, 2023
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
sinisaos commentedon Apr 25, 2023
@mastercoms I think
HTTP 201 CREATEDis a good response status code because the request was successful and led to the creation of a new resource. Sorry if I'm wrong.dantownsend commentedon Apr 25, 2023
I think what's going on is we're returning a
201fromPiccoloCRUD, butFastAPIWrapperhas the default of200. They should be consistent really - it should be a quick fix.piccolo_api/piccolo_api/fastapi/endpoints.py
Line 393 in 40d4316
sinisaos commentedon Apr 25, 2023
@dantownsend I don't think we should change anything because both
PiccoloCRUDandFastAPIWrapper,in my case, return correct201onPOSTrequest? Sorry if I don't understand correctly.dantownsend commentedon Apr 25, 2023
@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.
sinisaos commentedon Apr 25, 2023
@dantownsend Aha, now I understand! Here we can add

status_code=status.HTTP_201_CREATED,toadd_api_routeof POST method and it works.Should we do it for all methods?
dantownsend commentedon Apr 25, 2023
@sinisaos yeah, at least for any which don't return 200
sinisaos commentedon Apr 25, 2023
@dantownsend If you OK with this changes
I can try to do this tomorrow for all the methods to have the same status codes in the Swagger docs as in the
PiccoloCRUD.dantownsend commentedon Apr 25, 2023
@sinisaos Yes, that looks right.
post_singlereturn id of the inserted row instead of the row #255 as a duplicate of this issuejuneja-varun commentedon Sep 3, 2026
I'll take a shot at this.
juneja-varun commentedon Sep 3, 2026
Opened #338 with a fix for this.