⚠️ This lesson is retired and might contain outdated information.

Understand 2xx HTTP Status Code Responses

Pete Johanson
InstructorPete Johanson
Share this video with your friends

Social Share Links

Send Tweet

The 2xx family of status codes are used in HTTP responses to indicate success. Beyond the generic 200 OK status code, there are a set of more specific success status codes that provide additional context or details about the specific nature of the successful request/response. We will explore the available success status codes, and what additional information they convey.

[00:01] The 200 family of HTTP status codes is used to indicate success in responses. Let's take a look at an HTTP get. I'm a GitHub user, using the GitHub API.

[00:14] Here we can see the server has responded with a 200 OK HTTP status code. 200 OK is the generic 200 family of code to indicate a successful response. In addition to the 200 status code, there are more specific 200 family status codes that can be used to provide more context and more details about the kind of success. Let's take a look at creating a GitHub issue.

[00:50] Here we can see the server has responded with a 201 Created status code. This more specific one is letting our client know that they successfully created our new issue. In addition to the status code, because this has a 201 Created status, there's a location header that is used to indicate to the client the new URL for the newly created resource.

[01:15] Another status code that can be used for a server to indicate it is asynchronously processing a request is a 202 Accepted status code. Let's take a look at an example with the GitHub API when creating a fork of a project.

[01:34] Here we can see the server has responded with a 202 Accepted status code. Unlike 201 that may provide the location of a newly created resource, because our fork may take a while to actually be created by our service, 202 Accepted is used instead. This indicates we've successfully accepted the response, but that the newly created resource isn't immediately available.

[01:58] Another status code is available to indicate success, but omit a message body if there's no message body relevant to the success. Let's take a look at checking whether a certain gist on GitHub has been starred by my user.

[02:19] Here we can see the server has responded with a 204 No Content response. This is used to indicate that the star does exist for my user on this gist, but there's no other relevant message body that needs to be included. If this had been a gist that I had not starred, instead a 400 range of status codes would have been returned to indicate that star did not exist for my user.

[02:43] Lastly, there exists a status code to indicate that a partial response has been returned from the server. This is particularly relevant when downloading binary files, such as images, documents, PDFs, etc. Let's take a look by fetching part of my GitHub user's avatar image.

[03:05] Here we will use a range header to indicate we'd only like a partial range of the particular resource. You can see that the server has responded with a 206 Partial Content status code. In addition to that status code, it lets us know the specific content range that has been included, as well as the total content range that's available for that resource.

[03:28] 206 Partial Content, along with the content range header, is the way that certain downloaders can resume downloads when they've partially downloaded a file, by inspecting what bytes they already have received, and make a request for the remaining bytes.