litestar-org / litestar

Production-ready, Light, Flexible and Extensible ASGI API framework | Effortlessly Build Performant APIs
https://litestar.dev/
MIT License
5.53k stars 378 forks source link

DELETE method passes the point of no return ?! #924

Closed i-Ching closed 1 year ago

i-Ching commented 1 year ago
  1. Starlite version 1.44.0 does not allow delete method to return any result. It is impractical for real-life usage.

    #from your minimal example:
    @delete(path="/{user_id:uuid}")
    async def delete_user(self, user_id: UUID4) -> None:
  2. Starlette and FastApi allows DELETE method to return results: https://sqlmodel.tiangolo.com/tutorial/fastapi/delete/

  3. Aiohttp, Sanic and Quart allow DELETE method to return results too: https://sanic.dev/en/guide/advanced/class-based-views.html#defining-a-view https://subscription.packtpub.com/book/web-development/9781801076302/2/ch02lvl1sec11/how-quart-handles-requests

  4. Because "results of DELETE return" save our extra codes. It make programs simple and direct to match with SQLAlchemy results: Delete support the ability to return the number of rows matched after the statement proceeds https://docs.sqlalchemy.org/en/20/tutorial/data_update.html#tutorial-multi-table-deletes

My main point is: I request DELETE method of Starlite passing the point of some return, as same as other competitors https://youtu.be/D-TgDvyr3g4?t=132

Past the point of no return
The final threshold
What warm unspoken secrets
Will we learn
Beyond the point of no return?
Goldziher commented 1 year ago

Very poetic.

Its not about delete, delete can return a value. Status code 204 does not support content. You can change the status to 200 or something else and return a value.

Regarding other frameworks - you are welcome to try returning 204 with starlette and content and see what happens. Its simply that starlette and fastAPI default to 200 for delete, which is semantically wrong.