Web is a place where there are tons of computers talking to each other. As the web grew, it became clear that we needed a common and secure way to allow others to interact with our application. This need gave rise to Representational State Transfer Architecture or more commonly known as REST architecture. REST defines a set of constraints for how the web should behave.
The Client calls the server using http methods and gets a http response code and http response status along with the resource as the response. The most commonly used HTTP methods are
- GET: This the the most widely used request method. When the client makes a GET request, it means that the client is asking for the resource mentioned in the URI. Multiple GET request for the same resource will result in same response from the server.
- POST: The second most common request method. A POST request from the client comes with a request body that contains a structure of the resource itself. POST request is used to create the resource enclosed in the request body of a POST request. Every time we make a POST request, the server will create a new request even if the body of the request doesn't change.
- PUT: A PUT request, just like the POST request contains a structure of the resource in its request body. A PUT request tries to find of the resource is already present and if its present then update the resource and if its not present it will create the resource. Hence PUT request will always give same response for same request.
- DELETE: A DELETE request from the client means the client wants to delete resource.
The response codes from the server are in the following categories
When we get the expected response from the server. This includes the following status codes
- 200 OK: This means that the request was success. This can be the result for any HTTP methods.
- 201 Created: This means that the resource was created. This will be the response for either PUT or POST request.
Client error responses
When there is something wrong with the request made by the client we get one of the client error response.
- 400 Bad Request: The server was not able to understand the request due to as the structure of the resource in request body is not same as the one server expects
- 401 Unauthorized: The client is not recognized by the server and this is a resource only for recognized clients.
- 403 Forbidden: The client does not have access to the resource. Unlike 401, here the server is aware of the client but the client does not have access to the resource.
- 404 Not Found: The server cannot find the requested resource.
Server error responses
When there is something wrong with the server, then we get one of the server error response.
- 500 Internal Server Error: The server encountered a situation it doesn't know how to handle.
- 501 Not Implemented: The request method is not supported by the server.
- 503 Service Unavailable: The server is not available to handle the request. This might be due to the server being down for maintenance.