> For the complete documentation index, see [llms.txt](https://backend-course.cornellappdev.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://backend-course.cornellappdev.com/cheat-sheets/postman.md).

# Postman

## Download Postman

Highly recommend you install Postman as soon as the course starts! It will be crucial to assignments and practically any backend dev-ing.

{% embed url="<https://www.getpostman.com/downloads/>" %}

## Why use Postman

If you hit an endpoint in your browser, the best you can do is hit endpoints that are just `GET` requests (see the section below on how to hit an endpoint). There's no easy way for you to test parts of your backend API that handle `POST` and `DELETE` requests -- so how do you know if you are responding in the way that you coded and expected? Use Postman!

Postman lets you do all of these things with a super helpful user interface. You can even organize all of the endpoints your testing into folders and workspaces, as well as share them with whoever is collaborating with you on a project!&#x20;

## How to "hit" an endpoint in general

When you run your code locally (aka on local host), your endpoint at port `5000` can be reachable at all of these options:

{% embed url="<http://0.0.0.0:5000/>" %}

{% embed url="<http://127.0.0.1:5000/>" %}

{% embed url="<http://localhost:5000/>" %}

This is because `0.0.0.0`, `127.0.0.1`, and `localhost` all mean you're running off of local host! You can read more about the differences on [this stack exchange post](https://superuser.com/questions/949428/whats-the-difference-between-127-0-0-1-and-0-0-0-0).

#### Common mistake #1

If you can't hit your endpoint, ensure that you are also hitting the right port that your code is running on! This is usually declared somewhere at the bottom of your `app.py`:

```python
if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000, debug=True)
```

#### Common mistake #2

There's a difference between `http` and `https`, so make sure you are hitting `http`!

## How to make a GET request in Postman

1. Select `GET` from the dropdown to the left of the `Enter request URL` input text field bar
2. Input the endpoint receiving the `GET` request into the text field bar&#x20;
3. Click the blue `send` button
4. Postman will now show you either your successful `JSON` response at the bottom, or some errors for you to fix

### `GET` Query Parameters

GET requests can also have parameters, and there are two ways to hit an endpoint with parameters:

#### 1. Type in your `GET` parameters manually into the input text field bar

{% embed url="<http://localhost:5000/?key1=value1&key2=value2>" %}

where `key1` and `key2` are the names of your parameters, and `value1` and `value2` are the corresponding values (you can have as many as you want, but this example only has two key-value pairs).

For example, if I'm designing backend that returns some information about a student given their first name, last name, and age, I could type this URL into the text field input bar:

{% embed url="<http://localhost:5000/?first=john&last=doe&age=20>" %}

#### 2. Input your `GET` parameters into the table and let Postman automatically fill in your URL

![](/files/-Lweb9J5zXbWRsuFp3Bw)

Just type away under `Params` (select this option in the banner under the URL) and the checkboxes will automatically be checked and your URL will automatically have the params filled in!

## How to make a POST request in Postman

1. Select `POST` from the dropdown to the left of the `Enter request URL` input text field bar
2. Input the endpoint receiving the `POST` request into the text field bar&#x20;
3. Click on `Body` in the banner right below (next to `Headers` and `Pre-request Script`)
4. Select `raw`
5. Select `JSON` from the dropdown to the right of `raw`
6. Type in your `POST` request body in `JSON` format
7. Click the blue `send` button
8. Postman will now show you either your successful `JSON` response at the bottom, or some errors for you to fix

Here's an example of what a `POST` request could look like, with the `{ "first" ... "true" }` information being the `POST` request body written in `JSON` format.

![](/files/-LweeXrhJjNri-_3PtlJ)

Note that `JSON` can take in strings, integers, and booleans.&#x20;
