From the course: Learning REST APIs

Response header

From the course: Learning REST APIs

Start my 1-month free trial

Response header

- [Instructor] Any time you send a request to a REST API, the API returns some form of response to tell you what happened on its end. This response comes in the form of a head section and whatever content the resource provided. This head section is not normally seen by us humans, but instead used by the client to handle the return data. Every response from a REST API will have a head section and the contents of that head section will vary depending on the type of method you used and what type of resource you requested. To get just the head section of a response, we can send a head request to any resource. A typical response will look something like what you see here. Off the top, we learn what protocol was used, in this case HTTP 1.1 and we get the HTTP status message, in this case 200 OK, meaning the request went through as expected. Head requests will only ever return either 200 OK if we hit a resource that actually exists, or 404 not found if the URI were using points at nothing. Next we get meta data on the response, date and time of delivery, the content type, the type of server that delivered the content, transfer and coding, connection, caching data, the list goes on and on and on. All of this information tells the client about the data it's receiving and the environment it received it from. This information is then used to figure out how to parse the data and perform more actions. As an example, at the very bottom, you'll see content type is defined as application JSON, and that means any data that comes along with this head will be formatted in JSON and we need to parse it as JSON. You'll also see in some rest requests, you'll have content and coding gzip defined, meaning all the content that comes below is gzipped and we have to use gzip to unpack it. Depending on the complexity of the REST API and the data set it manages, the response header will change. For our purposes, the most important part is the HTP status message right here at the very top.

Contents