REST API Good Practices - nthieu29/icommerce GitHub Wiki

REST API Request

The primary used HTTP verbs are GET, POST, PUT and DELETE.

  • GET: Get a list of resources or a single resources.
  • POST: Create a new resource.
  • PUT: Update/Replace an existing resource.
  • DELETE: Delete an existing resource.

We should define our URIs for our service following:

REST API Response

There are really only 3 outcomes in the interaction between an app and an API:

  • Everything worked.
  • The application did something wrong.
  • The API did something wrong.

So we usually use 3 following HTTP codes for the responses:

  • 2xx - Successful responses
  • 4xx - Client errors - A json with error/more details should return to the client.
  • 5xx - Server-side errors - A json with an error should return to the client only when there is no security risk by doing that.