Status Codes


Status codes are vital for allowing a front end API consuming script to actually know of the type of result that is returned. Javascript can easily get the data but it may not know what type of data it is. Is it a normal JSON output? Is it an error? Is it unauthorized?

Along with all of the typical API responses will also be a certain status codes. Below are the list of status codes and what the causes them to be returned.

200 OK

This is returned on all GET, PUT and DELETE methods and therefore are returned on the read, update and delete actions.

201 Created

This status code is returned whenever the user creates a new entry into the API. These are returned on POST requests and therefore whenever the user uses the create action.

400 Bad Request

This is called whenever the client doesn't supply a token used for authentication.

401 Unauthorized

This is returned whenever the client supplies a token but it is not correct or if the user does not have a correct permission scope to access that endpoint.

405 Method Not Allowed

This is used whenever the user tries to specify an action that is not supported by the endpoint. For example, this can be called whenever the user tries to update a record (PUT) that can only be read (GET) or created (POST).

429 Too Many Requests

This is used if you have a rate limiting class on the resource and the client has hit their rate limit.

500 Internal Server Error

This is called whenever there has been an error on the server for whatever reason. These typically include database errors such as a duplicate email address or other related database errors.