Home

Tuesday, July 25, 2023

Different types of Rest API HTTP Status Code

2. What is HTTP?

Request from the browser ship to the server. And we will get the response from the server. The necessary element is what the format of the request and response are. This format is described via HTTP Hyper Text Transfer Protocol. When we enter the url in the browser it sends get request to that server. The server sends http response containing the html. Browser looks at the html and displays it.

Lets say, there is list of details and when we click the submit button, in these variety of eventualities commonly we are creating POST request. HTTP defines the header which is current in the request and the body of the request.

Also http defines the http techniques which are: GET, PUT, POST and DELETE. You can indicate what motion you are doing by way of using HTTP methods.

REST API Status code: Whenever the customer make request server need to response. Success on not. HTTP categorizing five extraordinary code.

This Status code begins from 100 and go up to 599. Not all of them are valid code. The first digit shows what type of the code belongs to.

The code starting with 1 XX are informational code like acknowledgment responses. We are now not the use of this code.

The code beginning with 2XX are success code. They point out that the server acquire a request from a client and process it successfully.

200: If your request get success, that response fame OK that indicates the status code 200.

201: is Created. this suggests successful resource creation. Lets say you have POST request on a collection uri like /messages and you were efficaciously able to create that message, you may want to return 200: OK pronouncing for success response. But better response code would be 201 created which especially stands for creational acknowledgment.

204: No content which you use when you don’t really need to send any content back. For example there is delete request. When you get a delete request you delete the resource. At this point you don’t have to send anything back. Because just resource got deleted. You could return 200 status. But still for more specific you could also send 204 no content which makes it really obvious to the client really intended to send nothing back.

300: the code starting with digit 3 are Redirection. Codes. These codes are used by the server to ask the client to do further actions to complete the request. For example it could be redirect asking the client to send the request somewhere else.

The codes 302: Found

304 : is Not modified is an error code which the server sends, when it needs to tell the client that there is nothing that has been modified. Lets say the client raise to get a resource, that already got before. Now the server can send the status code say, hey I already given you the resources little while back. There is nothing has changed since then. That’s why you are sending 304 rather than sending the whole response again.

307: is Temporary redirect. Or one of the 2 error code send by the server to ask the client say, hey don’t ask me , ask this other URL. This is redirect.

400 code indicates Client Error. These error codes are return client makes the error in the request. The request syntax could have been incorrect. Or the client requesting something that its not supposed to see.

400: Bad request which is blanket client error. The server is not able to understand the request.

401: Unauthorized. Which means the clients needs to sign and authorize themselves to see the resource.

403: Forbidden. Which means the clients may have authenticated but not have the permission to access the requested resource. They don’t have write access something like that.

404: Not found. You are sending the request. Let’s say the request URI may le say /messages/101. There is no message available with the id 101 you will get 404 not found status code. Because server will be able to find the resource.

415: Unsupported Media Type. Which means the client is speaking in a language that the server cannot understand. Which means some format the server cannot understand. In this case server response with 415 unsupported media type.

The 500 codes indicates the server error. The 400 codes are when the clients make error when the make request. 500 are server side error when response back. Basically the server is saying I got your request. It looks like a valid one. But something went wrong when I try to process it. So it returns the 500 codes.

500: internal Server error. This is the generic error code. The server get a request. The resources exist. Or otherwise you got 404. But something went wrong. When processing the request.in this case the standard practice is to send the error code 500 along with the error details in the body of the response.

Summary

We have looked into Different types of Rest API HTTP Status Code and What is HTTP .

Related Blogs:
Different types of Rest API Status Code

No comments:

Post a Comment

Spring Boot Rest API -Exception handling

Client is sending the request. Getting response. If everything is okay. Then we are good. But if something fails t...