Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Server \ How to choose the correct HTTP status code     - RM Environment Database RMAN Backup Strategy Formulation (Database)

- Bash difference in single quotes and double quotes (Programming)

- The Linux firewall is configured to use proxy (Linux)

- Linux / UNIX: Use the dd command to create a 1GB size binary (Linux)

- To setup CentOS LAMP environment (Server)

- Proper use Core Data multithreaded 3 ways (Programming)

- Java heap (Heap) and stack difference (Programming)

- Linux Command Tutorial: du command to view disk space (Linux)

- Boost notes --Asio - (1) a simple small example of synchronous communication (Programming)

- Realize screen recording and playback via Linux command (Linux)

- Security of data to create a safe .mdb database (Linux)

- Improve WordPress performance (Server)

- Linux kernel modules related to the management Comments (Linux)

- Ubuntu users install the Download Manager software Xdman 5.0 (Linux)

- Ubuntu is not in the sudoers file problem solving (Linux)

- Loop arrays in C language is not easy to find a bug (Programming)

- Ubuntu 15.04 / CentOS 7.0 to set custom boot (Linux)

- Ubuntu 14.04 set auto sleep time (Linux)

- CentOS / Linux NIC set IP address configuration (Linux)

- Ubuntu deployment Flask + UWSGI + Nginx Comments (Server)

 
         
  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
     
         
       
         
  More:      
 
- CentOS / Linux NIC set IP address configuration (Linux)
- Vi (Vim) keyboard map and its basic commands (Linux)
- Handle large data problems Bit-map method (Programming)
- PL / SQL how to make the program every few seconds to insert a data (Database)
- Scope of variables in Object-C (Programming)
- Manually compile Hadoop 2.6.0 under Ubuntu 14.04 (Server)
- Try to use Lets Encrypt (Linux)
- Linux kernel IPv6 protocol closed manner (Linux)
- shell script: MySQL startup script simple (Database)
- Mounting kit under Fedora Linux (Linux)
- Cobbler batch install Ubuntu / CentOS system (Linux)
- Linux install the Java Runtime Environment and the output Hello World under (CentOS) (Linux)
- Change the kernel boot sequence after CentOS 7 kernel upgrade (Linux)
- Linux Basics Tutorial: Combining awk delete data before the specified date hdfs (Linux)
- DB2 Version SQLJ to access Oracle Server (Database)
- Java implementation of stacks and queues (Programming)
- Ubuntu 14.04 VirtualBox can not start solution (Linux)
- APT-mirror using a four-step configuration Ubuntu local depot (Linux)
- MySQL database master never solve the synchronization method (Database)
- MySQL 5.6 use GTIDs build the master database (Database)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.