Friday, 22 April 2016

What are the guidelines to develop the REST API ?


1. Do not use GET method to change the data
  GET /users/101/enable
  GET /users/101?enable

    Use PUT or POST or DELETE (for modify, add and delete respectively) 
  PUT /users/101/enable


2. Use nouns instead of verbs
    GET /getUsers
  GET /users


3. Keep singular and plural nouns separate
    For getting multiple resources, use only plural nouns
    GET /users
  GET /user   -> Can be used for single resource


4. Provide version for API
  /dce/api
  /dce/api/v1

    
5. Provide features : Select, Filter, Sort and Pagination
  GET /users?fields=name,class,balance
  GET /users?class=gold
  GET /users?sort=+class,-balance
  GET /users?limit=10&offset=20


6. Use resources hierarchy
  GET /users/101/cards
  GET /users/101/cards/citibank


7. Use HTTP status codes for errors
    Also provide error code with message description in JSON format.


8. Use HTTP headers for formats
    Specify format in HTTP header : 

  • Content-Type for request format.
  • Accept for list of allowed response formats.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.