jeudi 9 mars 2023

Should I create an endpoint per HTTP method in my Django backend application?

I am developing a Django backend application with Django Rest Framework. Apart from having to write a lot of code, is it good practice to have a separate endpoint for each CRUD operation? Say I have an Organization model that I would like to create CRUD endpoints for. My usual approach is to create an endpoint ListCreateOrganization(generics.ListCreateAPIView) and map that to the path /organization/. Then create another endpoint /organization/<int:pk>/ for a RetrieveUpdateDeleteOrganization(generics.RetrieveUpdateDestroyAPIView) (assuming all CRUD operations apply). What are the scalability and performance concerns of this approach? What about creating five endpoints and mapping that to each operation:

  1. Create - /organization/create
  2. List (get multiple instances) - /organization/list/
  3. Get a single instance - /organization/<int:pk>/retrieve/
  4. Update a single instance - /organization/<int:pk>/update/
  5. Delete a single instance - /organization/<int:pk>/delete/

Aucun commentaire:

Enregistrer un commentaire