Every response to an HTTP request has a status code identifying the outcome of the request. These status codes are crucial for us to understand when working with protocols using HTTP/HTTPS such as REST APIs and RESTCONF.
Many certifications like the Cisco DevNet Associate require you to understand certain status codes. You will also be required to determine what status code was received based on a problem description.
Status codes are generated by the responding server and are three-digit numbers appearing in the first line of the response header along with its meaning. Take a look at this sample HTTP response:
HTTP/1.1 200 OK
Date: Sun, 10 Oct 2010 23:26:07 GMT
Server: Apache/2.2.8 (Ubuntu) mod_ssl/2.2.8 OpenSSL/0.9.8g
Last-Modified: Sun, 26 Sep 2010 22:04:35 GMT
ETag: "45b6-834-49130cc1182c0"
Accept-Ranges: bytes
Content-Length: 12
Connection: close
Content-Type: text/html
Hello world!
It’s important as developers and network automation engineers to understand what these response codes are and what they represent.
More importantly is how we respond to specific status codes in our own code. For example, you may want to have the program retry the request a specified amount of times if you receive a non-success code.
Status codes are broken down into five categories and you can identify the category by the first number of the code.
- 1xx – Informational
- 2xx – Success
- 3xx – Redirection
- 4xx – Client Error
- 5xx – Server Error
While there are many status codes to learn, the DEVASC exam doesn’t require you to know all of them. The table below offers the basics of each status code you should be very familiar with for the exam.
Code | Meaning | Description |
100 | Continue | This interim response indicates that the client should continue the request or ignore the response if the request is already finished. |
200 | OK | The request succeeded. The result meaning of “success” depends on the HTTP method. |
301 | Moved Permanently | The URL of the requested resource has been changed permanently. The new URL is given in the response |
302 | Found | This response code means that the URI of requested resource has been changed temporarily. Further changes in the URI might be made in the future. Therefore, this same URI should be used by the client in future requests. |
304 | Not Modified | This is used for caching purposes. It tells the client that the response has not been modified, so the client can continue to use the same cached version of the response. |
400 | Bad Request | The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing). |
401 | Unauthorized | Although the HTTP standard specifies “unauthorized”, semantically this response means “unauthenticated”. That is, the client must authenticate itself to get the requested response. |
403 | Forbidden | The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource. Unlike 401 Unauthorized , the client’s identity is known to the server. |
404 | Not Found | The server can not find the requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist. |
405 | Method Not Allowed | The request method is known by the server but is not supported by the target resource. For example, an API may not allow calling DELETE to remove a resource. |
408 | Request Timeout | This response is sent on an idle connection by some servers, even without any previous request by the client. It means that the server would like to shut down this unused connection. |
414 | URI Too Long | The URI requested by the client is longer than the server is willing to interpret. |
429 | Too Many Requests | The user has sent too many requests in a given amount of time (“rate limiting”). |
500 | Internal Server Error | The server has encountered a situation it does not know how to handle. |
501 | Not Implemented | The request method is not supported by the server and cannot be handled. The only methods that servers are required to support (and therefore that must not return this code) are GET and HEAD . |
502 | Bad Gateway | This error response means that the server, while working as a gateway to get a response needed to handle the request, got an invalid response. |
503 | Service Unavailable | The server is not ready to handle the request. |
504 | Gateway Timeout | This error response is given when the server is acting as a gateway and cannot get a response in time. |
The status codes listed above are also the more common ones you’ll encounter for a majority of your work in network automation.
Note: As time allows, I’ll be going more in depth on several of the status codes.