Every response is contained by an envelope. That is, each response has a predictable set of keys with which you can expect to interact:
#!
{
"meta": {
"code": http_code
}
"data": {
...
}
}
META
The meta key is used to communicate extra information about the response to the developer.
If all goes well, you'll see a code key with values 200s or 300s. However, sometimes things go wrong, and in that case you might see a response like:
#!
{
"meta": {
"code": 400,
"message": "..."
}
}
DATA
The data key is the meat of the response. It may be a list or dictionary, but either way this is where you'll find the data you requested.
These are the HTTP response codes that you can expect to receive when making an HTTP request. Note that responses in the 200s and 300s are considered successful, and those in the 400s and 500s are considered errors.
GET Possible response codes for a GET request:
- 200 OK
- 401 UNAUTHORIZED
- 404 NOT FOUND
- 500 SERVER ERROR
- 503 SERVICE UNAVAILABLE
POST The following table describes the possible response codes for a POST request.
- 200 OK
- 201 CREATED
- 400 BAD REQUEST
- 401 UNAUTHORIZED
- 404 NOT FOUND
- 405 METHOD NOT ALLOWED
- 500 SERVER ERROR
- 503 SERVICE UNAVAILABLE
When an error occurs, the returned JSON will contain the status code and error/s.
#!
{
"meta": {
"code": 400,
"message": "..."
}
}
If there are several errors in a POST call (create an object), the returned JSON will look:
#!
{
"meta": {
"code": 400,
"errors": {
"parameter": "Error message",
...
}
}
}