Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RESTful API design best practices [closed]

Tags:

rest

api

I am current writing an API layer for my project, and am struggling with trying to figure out a good design approach for the following scenario:

  1. All users have a list of books
  2. Each list can be accessed via an ID
  3. Users can add and delete books at will

Currently, I'm not sure which the best approach would be:

1) PUT - /api/list/{listID}/{bookID} - Add book to specified list
   DELETE - /api/list/{listID}/{bookID} - Remove book from specified list
2) PUT - /api/list/{listID} - Send XML data to server that contains bookID and action
   <list_payload>
       <action>{delete|add}</action>
       <bookID>{bookID}</bookID>
   </list_payload>

Any insight would be appreciated.

like image 913
jfrey Avatar asked Aug 11 '11 13:08

jfrey


1 Answers

I think like this

1)POST - /api/lists/{listID}/books - Add book to specified list
2)PUT - /api/lists/{listID}/books/{bookID} - Edit book from a specified list
3)DELETE - /api/lists/{listID}/books/{bookID} - delete

for List

POST - /api/lists Add list
PUT - /api/lists/{listID} Edit list
DELETE /api/lists/{listID} Delete list
like image 74
Dnyan Waychal Avatar answered Sep 21 '22 06:09

Dnyan Waychal