In actual work, the front and back end cooperation basically only use GET/POST, and the corresponding status code is encapsulated in 200, instead of using HTTP level status code. So commonly see 200/404/500 is the most, other very rare, see hind do not know what to use a bit ~

No matter how cumbersome it is to start with, the interface should be designed to follow the standard HTTP protocol, and only need to be used twice

  • In appearance, it is easy to see what the result of this request is
  • Also, many status code browsers do some processing automatically

4.1 status code

The purpose of a status code is to describe the result returned when a client sends a request to a server. It consists of two parts

  • 3 digits
  • The reason the phrase
category The reason the phrase
1XX Informational The received request is being processed
2XX Success Request processed
3XX Redirect Redirect, the browser needs to request again
4XX Client Error Client error
5XX Server Error Server error

4.2 2 xx success

  • 200 OK
    • The GET method returns the corresponding entity
    • The HEAD method does not return entities
  • 204 No Content
    • Success, but no return entity
    • Used to modify or tell the server that processing is OK, the client just needs to know if the server is processing
    • Can reduce traffic compared to 200
  • 206 Partial Content
    • The scope request was successfully executed
    • Compared with 200 one-time requests, this function saves traffic and speeds up interface display

4.3 3XX Redirection

  • 301 Moved Permanently
    • A permanent change
    • When you return, specify a new Location header field, and the browser automatically relocates it
    • Used for picture position change/interface path change
  • 302 Found
    • A temporary change
    • The difference with 301 is that the client may make a different decision
    • For example, if a link has been saved to a favorites folder, 301 will change the favorites folder, but 302 will not
  • 303 See Other
    • The requested resource corresponds to the new URI
    • The difference from 302 is that the client is explicitly required to access the new URI using the GET method
    • Can be used for high latency data download, send a request, the server returns a new link, the client itself after a few seconds to access the new link
  • 304 Not Modified
    • The server resource is unchanged and the client cache is used directly
    • Conditions can be attached to sending a request, such as searching for resources updated within 3 days. The following request header fields are supported
      • If-Modified-Since
      • If-Non-Match
      • If-Range
      • If-UnModified-Since
  • 307 Temporary Redirect
    • Same as 302
    • The difference is that GET is not required to access the new URI

4.4 4XX Client Errors occur

  • 400 Bad Request
    • Request parameter error
  • 401 Unauthorized
    • unauthorized
    • Used not logged in/logged out
  • 403 Forbidden
    • Access denied
    • This parameter is used when permissions are insufficient
  • 404 Not Found
    • Resources do not exist

4.5 5XX Server Error

  • 500 Internal Server Error
    • Server side bug
  • 503 Service Unavailable
    • The server is down.
    • The server is overloaded or being maintained