Beginners Introduction to Response Handling (pt2)
Tags: webdev, javascript, beginners
Published: 2021-12-24 22:05:39

In the _[previous article](https://dev.to/mod5ied/a-beginners-introduction-to-making-api-requests-unsplash-api-2lfk)_, we talked at length about how to make a request to a server, and also about the structure of requests, but in this article we will be diving deep into **HTTP response** as it relates to requests. 
An HTTP response is basically made by a server to a client reacting to a request. Its aim is to provide a resource back to the client (browser) that requested the file, or to inform the client about an error which occurred while processing the request; An error you might ask, yes and it’s worth noting that bad or invalid requests most often leads to an error as a response. It is a two-way process: a server can only give a response when it gets a request.

![status-code](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8fgt69n0s1xb8svxb6ic.jpg)

An important technical concept to understand to be able to grasp what response are all about, and that is ‘**HTTP status codes**’. “_Oh, another technical jargon!_”, one thing you have to understand is that, the server issues an HTTP status code in response to a client’s request. In simpler terms, a user makes a request for a resource, the web server processes that request and if the resource is found or present, the server responds with a status code befitting that operation.

![box-tag](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8eyy1hv98fg2yjv4gk3n.jpg)

A response can be likened to a box that has a bold tag on it to give a quick and brief peek into what’s actually inside, it could be money who knows right? Similarly, an HTTP response is the Box, an HTTP status is the bold tag on the box (the box is the actual resource returned by a server to a client). That was a bit better and refreshing right?
Now to understand this Box (response) properly let’s look at each individual parts separately, starting with the bold tag (HTTP status code) that gives a brief peek. HTTP status codes comes in forms of 3-digits and split into identity 5 categories: `(1xx, e.g. 101, 102)`, `(2xx, e.g. 200, 202)`, `(3xx, e.g. 300, 305)`, `(4xx, e.g. 400, 404)` and `(5xx, e.g. 501, 503)`.
The first category `(1xx)` is an _information response_, the second `(2xx)` denotes _success_, `(3xx)` flags a _redirection_ – most commonly used to state that a resource has been moved from its original state. The fourth `(4xx)` you may have seen while surfing the web – a `404` error, that states that a resource was not found. Finally, `(5xx)` occurs when there is a _server error_.

Understanding the nature of these status codes helps a developer to know what to expect and also the next line of action should they appear. Hence, HTTP status code are a vital and integral part of a HTTP response that shouldn’t be overlooked. Next, we would now explore the fun part of the box (response), the goodies!! The content of a response can be in any of a number of format. They all span under a common type – MIME which is a Media type. This can specify the format of the data as a type/subtype e.g. `text/html`, `text/xml`, `application/json` or `image/jpg` etc.
The response can be in any of the types – **JSON**, **XML**, **BSON**, etc. and can be converted to any of these during the GET action or can be done after the response has been returned from the API. 
In the next article, we would be talking about the concept of _Content-Type headers_ and how important they are in handling data response gotten from a server. Keep in touch!
Come on guys like and follow this dude to keep getting quality contents like this.