Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RESTful data structure patterns

I tried Googling and searching everywhere, but couldn't find a definitive authority on this topic. While being true to REST principles, how should I design the HTTP interface for:

  1. An ordered list (get, add, insert into position, reorder, remove)

  2. A set (get, add, remove)

  3. A hash-table (get, add, remove)

NOTE: These data structures are to contain references to existing resources with known ids

like image 323
dadads Avatar asked Jun 11 '12 08:06

dadads


People also ask

What is a RESTful pattern?

Representational state transfer (REST) is an architectural design pattern for APIs. APIs that follow this pattern are called REST APIs or RESTful APIs. REST sets certain standards between computer systems on the web that make it easier for systems to communicate with each other.

Which design pattern is used in REST API?

REST is a HTTP design pattern, 'the right way to do HTTP'. When implemented according to the REST pattern, HTTP is a client-server protocol with which clients can query and manipulate the resources of a server, like: 'Create a new resource on this URL'

What are the 4 most common REST API operations?

These operations stand for four possible actions, known as CRUD: Create, Read, Update and Delete. The server sends the data to the client in one of the following formats: HTML. JSON (which is the most common one thanks to its independence of computer languages and accessibility by humans and machines)


1 Answers

That's how I would do it for an ordered list and hash table. I guess the methods would be the same for a set and a list:

Ordered list

Get item 123:

GET /list/123

Append an item to the list:

POST /list/

Insert new item into position 5:

POST /list/?position=5

Move item 123 to position 3:

PUT /list/123?position=3

Delete item 123:

DELETE /list/123

Delete item at position 3:

DELETE /list/?position=3

Of course, your API should update the indexes of all the elements when doing insertion and deletion.

Hash table

Get item "somekey":

GET /hashtable/somekey

Add item "somekey":

POST /hashtable/somekey

Remove item "somekey":

DELETE /hashtable/somekey
like image 156
laurent Avatar answered Oct 31 '22 15:10

laurent