DEV Community

Cover image for Requests and Response for Beginners
Patrick
Patrick

Posted on

Requests and Response for Beginners

Have you asked the waiter at a restaurant to get you a dessert and they served you exactly what you wanted? Have you also asked for a Chicken-soup but got Chips instead? Well, believe it or not this is very similar to making requests and receiving responses on the web.
From the previous article we understood that we can make requests to a server via a link or a portal commonly called an endpoint or an API; the server processes this request that we have made prepares a response accordingly and passes it back to us via the endpoint, hence we can work with the response as we please.

request
A request could be of a number of type, we have the GET request: this is one of the most common forms of request programmers and developers alike often use to get a resource from a server. Another type of request is the POST request: this is a type of request that’s most commonly used in connotation to submitting a resource or a data to the server. It instructs the server to accept and store a data from the user/sender. We have other types of requests such as “PUT, DELETE, PATCH, HEAD, CONNECT”. Note: all these can be more specifically termed – http requests.
A response on the other hand is gotten or received for the server in a number of formats, it could either be a blob, a JSON (JavaScript Object Notation) data etc. Now to use this response, developers usually parse the response into other usable format (by default the browser returns a response in a format that is not readily usable), example the JSON format. It is always important to parse a response for the above reason.

bad-request
Note that, valid requests to a server via its endpoint leads to a successful or complete response. When you make an invalid request, the server could flag it as a bad request and reject, throwing an http status code to further explain the nature of that request.

Having understood what requests are, we can now see how it relates to responses and how the server reacts to this via its endpoint or API. This is an interesting way to understand the concept of request and response which are also one of the core foundations of web development we should all understand. More interesting articles like this are available.

Top comments (0)