REST API Web Services
Overview
A REST web service is an alternative to SOAP-based communications between servers. All the communication between the REST client and the server occurs on the standard HTTP protocol where the request information is placed in the HTTP Entity field. We can picture a REST client is a simplified HTTP client that communicates with the server.
REST Web service principles
The principles on which REST web services are based are as follows:
- Rest web services are based and use HTTP protocol methods like POST, GET, PUT, DELETE, etc.
- Just like HTTP, REST web service calls are stateless.
- The request/ response data payload uses content types like XML, JSON etc.
- The REST endpoints expose directory structure like URLs.
REST Response codes
Some example Rest API response error codes are as follows:
20x response code indicates a successful Rest API call. The API request was received and processed by the server and, the API response is received by the rest client.
40x response codes indicate API error conditions.
- 400: Bad request. Please check the API request format.
- 401: Unauthorized. This error indicates API authentication or authorization errors. Check for valid username/password, API access tokens, ACLs, etc.
- 404 Not found. This error indicates that the API endpoint is not valid, exposed by the server, etc.
- 405 Method Not Allowed this error indicates that the rest client is specifying wrong HTTP method.
50x error codes generally indicate server errors.
500 Internal server error. The server encountered an exception during the process of the API request. We can get a stack trace in the server logs for this kind of errors.
503 Service Unavailable. We generally get this error when the server rate limits or throttles the API request.