1

How would one use Django DestroyAPIView and DetailAPIView and still maintain generally accepted practices of RESTfulness?

If I understand REST correctly it should work as follow (only one example)

/api/game/222

then 1 view class(generics.DetailAPIView) or method, in Django would be created to handle the call

In a REST world, I believe we would use a generic API class to handle the methods (get,...)

But if I wanted to use the class(generics.DestroyAPIView) to handle the calls to delete a game. then I would have to use

/api/game/delete/222

to send the request to the correct view.

It seems to me this is not consistent with RESTFULness. for the delete method of the HTTP should be used to send the delete request and use the same pattern matching /apt/game/222 to delete the game. It's redundant.

Question: Am I missing something?

In summary

option 1:

/api/game/delete/222 (DestroyAPIView)
/api/game/detail/222 (DetailAPIView)

option 2

/api/game/222 (RetrieveDestroyAPIView)

I guess either way works, and as long as it's clear and consistent as stated below. There is no "right" way.

Shiplu Mokaddim
  • 56,364
  • 17
  • 141
  • 187
Kevin S
  • 25
  • 1
  • 6
  • 2
    You can just send a `DELETE` verb to `/api/game/222` in order to delete the game. This is one of the basic concepts behind REST. – Burhan Khalid May 27 '17 at 14:25

1 Answers1

0

I not sure 'RESTFULness' affect what you are asking here. It is perfectly fine to have different matching pattern as long as it make sense.

In the example given, usually we do not have /api/game/222 as a generics.ListCreateAPIView. This is because List return a list of all game, we do not pass a id in. Create is trying to create a new Game. You do not have id yet because it is not in database, therefore both of the matching pattern should usually be /api/game/ instead.

/api/game/222 - such pattern, we usually use for generics.RetrieveUpdateDestroyAPIView because with a given id in url, we can get the correct Game object to either retrieve, update or delete it.

Regarding the Restful API, the answers in this stack overflow question explain more about 'Restfulness'.

Zac Kwan
  • 5,587
  • 4
  • 20
  • 27
  • i updated the question to better reflect what i was asking. But I believe the answer is your first sentence. "as long as it makes sense" – Kevin S May 30 '17 at 12:39