Interacting with the Simple Express App using Postman
Tags: beginners, node, express, postman
Published: 2020-08-31 18:12:08

You're familiar with the concept of modularity from OOPS, right? So, my introduction is not in this post. :laughing:

{% post dsp9107/how-did-i-start-my-tech-journey-53ia %}

---

# Introduction

Postman is an API client which we are gonna use to interact with this Simple Express App.

{% github dsp9107/Simple-Express-App no-readme %}

> Postman is a collaboration platform for API development. Postman's features simplify each step of building an API and streamline collaboration so you can create better APIs—faster.

We'll be referring to this post to set up our Simple Express App.
{% post dsp9107/understanding-the-simple-express-app-node-js-10j5 %}

The agenda is to understand how an API makes client-server interaction convenient :seedling:

# Contents

- [Introduction](#introduction)
- [Setup](#setup)
  - [Prerequisites](#Prerequisites)
  - [Windows](#windows)
  - [Linux](#linux)
- [Usage](#usage)
  - [Building a Request](#building-a-request)
  - [Receiving a Response](#receiving-a-response)
  - [Another Request](#another-request)
- [Conclusion](#conclusion)
- [References](#references)
- [Further Reads](#further-reads)

# Setup

Before getting down to the interaction part, let's set up our workspace.

### Prerequisites

- VS Code
- Node.js
- Simple Express App
- Postman

### Windows

- Follow [these steps](https://dev.to/dsp9107/understanding-the-simple-express-app-node-js-10j5#windows) if you do not have the first three prerequisites.
- Get [Postman](https://www.postman.com/downloads)

### Linux

- Follow [these steps](https://dev.to/https://dev.to/dsp9107/understanding-the-simple-express-app-node-js-10j5#windows#linux) if you do not have the first three prerequisites.
- Install Postman
```
sudo snap install postman
```

# Usage

- Open Postman
- Sign up if you want or just click on “Skip signing in and take me straight to the app”
- Click on the `+` button up in the bar which looks like the Browser Tabs bar.

Let's take a look around and figure out what all components of Postman we actually need to care about as beginners.

We'll be utilizing Simple Express App's [API Documentation](https://github.com/dsp9107/Simple-Express-App/blob/master/api/queryParams.md) to get familiar with Postman :grin:

### Building a Request

![Building a Request](https://dev-to-uploads.s3.amazonaws.com/i/8zfl5247q4ze0j6fihyo.png)

- HTTP Method

See that `GET` in the extreme left? Clicking on that drops down a list of all the HTTP methods Postman supports. Leave it as it is.

- URL

Just right to the Methods Dropdown is the URL bar. Enter this URL
```
localhost:9107/queryParams?someKey=someValue
```

### Receiving a Response

![Receiving a Response](https://dev-to-uploads.s3.amazonaws.com/i/dyntix4zp9xm8uxb0dlf.png)

Clicking on **Send** will get you this response on the right of your window.

You can see that the server returned what we sent it as query parameters. So, we can send it as many query parameters as we want and it'll just send those back in the response body.

At the top, we can see some information in green. Those are
- **HTTP Response Code** - HTTP has some response codes defined. `200` indicates that the request has succeeded.
- **Response Time** - The time it took for the server to reply to our request.
- **Response Size** - This includes the headers, body, and if any cookies returned by the server.

We can also hover the cursor over the respective tags for more details.

### Another Request

Let's send the same data, we sent as a query parameter, in the request body so that it isn't visible in the URL of our request.

- Change the method to `POST`
- Change the URL
```
localhost:9107/bodyJSON
```
- Just below the URL bar is **Body**, put `{"someKey":"someValue"}` in it.
- Hit **Send**

![Another Request](https://dev-to-uploads.s3.amazonaws.com/i/nd4zjiygrvtyirb0kkq3.png)

It should look like this. :grin:

# Conclusion

This is how you can use Postman to communicate with any server. You just need to be able to interpret the documentation of the API. I don't think there's any convention for an API Doc but they all have pretty much the same information which we have seen above. Remember to have fun :grin:

# References
- [Postman Documentation](https://learning.postman.com/docs/getting-started/introduction)

# Further Reads
- [How to Use Postman to Manage and Execute Your APIs](https://www.blazemeter.com/blog/how-use-postman-manage-and-execute-your-apis)