As a developer, we spend a lot of time dealing with data requests and responses between the front and back ends every day, which requires us to have enough HTTP knowledge. This section will discuss HTTP status code.

What is HTTP status code

Fernando Doglio in his book – REST API development using NodeJS defines the status code as:

A number that summarizes the response associated with it.

When a client makes a request to the server, the server provides an HTTP (Hypertext Transfer Protocol) response status code, which allows us to see what is happening on the back end of the site and identify errors that need to be fixed.

HTTP status code cheat sheet

Response information

1xx: temporary response, indicating that the client should go to 📝

The state of 1xx is handled directly by the browser HTTP library without being known to the upper layer application

successful

200-OK: transfer successful 💯

The request is successful

201-created: creates 🆕

The resource is created and the server is confirmed. It is useful for responding to POST or PUT requests. In addition, new resources can be returned as part of the response body.

204-no content: No content 👌🥚

The operation request was successful, but nothing was returned. Useful for operations that do not require a response body, such as DELETE operations.

205-reset Content: resets Content 🐾

The response message does not contain the body part of the entity, but differs from the 204 response in that the requester is required to reset the content

redirect

3xx: These are used when the server notifies the client of a change in the target of the request and wants the client to process it further.

301-Moved permanently: permanently move permanently 🏃

Used to inform the browser that the requested file has been moved and that it should request the file from the location provided by the server and remember the new location for future reference. This can only be used for HTTP GET and HEAD requests.

This resource has been moved to another location and returned to that location. This header is especially useful when the URL changes over time (especially due to versioning, migration, or some other disruptive change), keeping the old header and redirecting it back to the new location allows the old client to update the time it references itself.

302-found: Temporary redirection 🕘

Similar to 301; But it’s a temporary redirect. It directs the client from the old resource to the new resource, but it does not tell the search engine to update the index of the page. Tell the client to browse to another URL.

304-not Modified: The client cache is Not updated 👯

The client already has a cached version, which is told to the server in the Request. When the server finds that there is no update through time or tag, it will return a 304 status code without body

307 – Temporary Redirect: Temporarily move 🚶

Temporary redirect, similar to 302, but expects the client to keep the request method the same and send the request to the new address

Client error

4xx: Defines a client error, which is where the server thinks the Web browser is wrong.

400 – Bad request: bad request 👎

There is a problem with the request being made (for example, some required parameters may be missing). A good complement to the 400 response might be an error message that the developer can use to fix the request

401 – Unauthorized: 🚫🚫️

This is especially useful for authentication when the user with the request cannot access the requested resource

403-forbidden: forbidding ⛔️ – Resources are not accessible, but unlike 401, authentication does not affect the response.

This is usually issued when the requested file is valid but not available, usually because the Web server does not allow the file to be made available to the client due to server-side permissions.

The difference between 401 and 403:

  • I went to find someone, but the doorman said he didn’t know me and wouldn’t let me in
  • I went to find someone, and the doorman said he knew me, but I couldn’t come in because I wasn’t worthy

404-Not Found: The requested resource is Not Found 🔍🔎🔦

This is probably the most common and frequently made mistake. This problem occurs when a Web browser requests a file that does not exist on the server.

405 – Method not allowed ✖️🙅

HTTP verbs ** (e.g. POST, GET, PUT, etc.) are not allowed on resources ** – for example, perform PUT on read-only resources.

418: It’s a Teapot, an April Fool’s Joke from IETF 😈

Server error

5xx: Defines server side errors. Although the client provided a valid request, these were errors that occurred on the server side.

500 – Internal sever error: internal server error 🙈

This is an unfortunate obscure generic error code. It is emitted whenever the server encounters an error that it believes does not match any more specific error code.

501-Not Implemented: 🙀

The server either does not recognize the request method or does not support the request.

502 – Bad Gateway: error Gateway 🤦♀

This happens when a Web browser contacts a Web server that acts as a proxy for another server and gets an invalid response from the other server.

503-service unavailable: The service is unavailable 🤭👻

This is typically encountered in the case of a temporary error (the server is temporarily overloaded or is down for maintenance), where the server cannot handle the request and can try again later

series

For more on this series,Click on the Github homepage

Go last, welcome to pay attention to: front-end bottle jun, daily update