Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Server \ How to choose the correct HTTP status code     - E: Sub-process / usr / bin / dpkg returned an error code (1) error solution (Linux)

- lolcat: an output terminal rainbow effects in the Linux command-line tool (Linux)

- Install Oracle 11g illustrations and dependent libraries under SUSE11 (Database)

- File sharing and fork function (Programming)

- Linux compiler of GCC (Linux)

- Build your own Web server under Ubuntu Linux system (Server)

- curl Usage: Being the first site header and status codes (Server)

- Linux find command detailing (Linux)

- Linux operating system security can not be ignored (Linux)

- Hadoop 2.2.0 installation development environment (standalone pseudo-distributed mode) (Server)

- C ++ type conversion and RTTI (Programming)

- Why did not Oracle privileges can also log in with sysdba (Database)

- Automatic and Manual Proxy Settings Switch GNOME Shell Extension Proxy Switcher Recommend (Linux)

- To install GCC development environment under SUSE11 (Linux)

- SpringMVC the use of interceptors (Programming)

- PHP interview questions of design patterns (Programming)

- Why is better than Git SVN (Linux)

- Ubuntu 15.10 install the latest Arduino IDE 1.6.7 (Linux)

- Linux IO redirection (Linux)

- How to Install Focuswriter 1.4.5 (Linux)

  How to choose the correct HTTP status code
  Add Date : 2018-11-21      
  As we all know, every HTTP response will be provided with a status code, but for many developers, most usually use several status code is nothing less than 200,400,404,500 and so on. That many other applications in which the state code scenario, when to use what has become a status code worthy of our deep thinking problem. Even in companies like Facebook, those clever API developers may be constructed only 200 returned. To this end, Michael Kropat dedicated to the author analyzes various application scenarios status code, and why do we so carefully distinguish different status code, and also talked about the benefits of doing so.

What is even simpler than that returns an HTTP status code things? Page rendering it? If you render, then return to 200 pictures. Page does not exist? That is 404. We need to redirect the user to another page? Then use 302, maybe 301 lines.

Everything is so simple, but if someone told you, you do not have to REST way to do things, you may have to wake up. Are new resources returned to the RFC-compliant, Roy-Fielding Recommendation status code? It is only 200? Maybe 204 No Content, 202 Accepted, or is it 201 Created?

The problem is that the official HTTP / 1.1 Guide (RFC) was originally released in 1997. At the time we are still using Netscape Navigator, 33.6kbps modem surfing the debugger it. This is like using the same Sun Tzu in the modern business strategy. These valuable suggestions and will not end with the passage of time and change. However, we need to really understand them.

If you have a visual tree is like, it can help you quickly identify with your situation coincides with a state code, so you can not ignore those related to the.

We found that many people will fall into one, and put forward such as "this situation should still use 503 Service Unavailable 404 Not Found it"? stop. If you think about a specific status code in a completely different response categories, it shows that your approach is completely wrong.

I make a few points before continuing:

You do not have to listen to me, please check directly with the RFC 7231 httpstatuses.com
I is intended for developers who create sites or use the REST API
I will respond to code broadly divided into three categories

Finally, mention one thing: I did not actually qualified to express their views on this subject, I just read some of the RFC and the development of some APIs only. If you think I am wrong, or you do not use state codes tend to use, then please comment at the end the middle finger out, we can discuss.

Why is it important status codes

Although Facebook in a lot of smart developers when building APIs return only 200, but I want to say is, the status code is indeed very important. Existing state code for modern websites / API is a little too broad. If the response you want to apply a specific format to include some details, such as which field validation fails, the reasons for that, which would allow clients to a more meaningful way to handle the response. That being the case, why not many take the time to look at those "less common" HTTP status code it?

Turning Why is the use of specific status code is very important when one of the reasons people love to mention is HTTP is a hierarchical system, there may be a proxy between the client and server, cache, or other HTTP libraries if meaningful response code, it will make it all better workplace. However, I think this explanation is untenable, for example, the future we all use on a HTTPS, we have lost all agents and disabled caching node, then you can say what status code is useless?

Here, I think I want to talk about the status code is still a very important three reasons:

1. The client may behave differently (or can easily be extended to deal with) for different status code:

301 Moved Permanently 302 Found for Google and other search engines as well as SEO metaphor
301 Moved Permanently cached meaning, while 429 Too Many Requests meaning no cache, and so on
Client libraries can handle 429 Too Many Requests by a time delay after the retry request
The client library may take a similar approach 503 Service Unavilable
2. Many state codes indicated may be processed through a special response.

Returns 405 Method Not Allowed 404 instead of APIs makes me crazy sometimes, "I was mistyped URL or HTTP using the wrong way to do that"?
Correctly distinguish 502 Bad Gateway 500 Internal Server Error and let you save a lot of debugging time.
3. Regardless Believe it or not, there are many popular APIs to establish a number of conventions, for example, returned 201 Created, 429 Too Many Requests, or 503 Service Unavilable. If you follow these conventions, then the user will be easier to use in your site / API, the encountered problems easier to solve.

If you encounter problems when using the HTTP status code, you can also refer to the following resources:

HTTP status code reference
HTTP status codes used by world-famous APIs
HTTP status codes visualized as a subway map
Status Codes To Cat Memes As a Service
Status Codes To Dog Memes As a Service
- Spring Data JPA call a stored procedure examples (Programming)
- Java development environment to build under Ubuntu (Linux)
- Linux6.1 / 6.5 dual-NIC Binding (Linux)
- In the case of using cgroups Ubuntu 14.04 and Docker (Linux)
- CentOS-based Kickstart automated installation practice (Linux)
- SSH without password (Linux)
- Android source code compiled fatal error solutions (Programming)
- Ubuntu install Eclipse can not find JAVA_HOME problem (Linux)
- When should I use Angular 2 (Programming)
- CentOS 6.5 / Linux restart network card being given Determining if ip address x.x.x.x is already in use (Linux)
- HomeKit Human Interface Guidelines (Linux)
- 22 Port weak passwords and SSH connection program of the Linux server (Linux)
- Java reflection Introduction (Programming)
- Python2 ---- function using dictionaries (Programming)
- MySQL time field based partitioning scheme summary (Database)
- To create a full command line Android Build System (Linux)
- 25 Git Advanced Skills (Linux)
- Oracle 11g How dataguard master repository to Oracle single instance data recovery (Database)
- Java memory area (Programming)
- Linux environment SSH login password instead of using the RSA Certificate (Linux)
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.