# 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

![](https://3452473873-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lu9Zw53dmTuhqAq-8K8%2F-LweEWKup_8x33R2PbE6%2F-Lweb9J5zXbWRsuFp3Bw%2FScreen%20Shot%202019-12-21%20at%202.37.11%20PM.png?alt=media\&token=0373a821-330e-46cd-a68c-be79876f0b06)

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.

![](https://3452473873-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lu9Zw53dmTuhqAq-8K8%2F-LweEWKup_8x33R2PbE6%2F-LweeXrhJjNri-_3PtlJ%2FScreen%20Shot%202019-12-21%20at%202.52.50%20PM.png?alt=media\&token=6e8e1c68-1efa-4b87-aa8f-0c43146adbe4)

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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://backend-course.cornellappdev.com/cheat-sheets/postman.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
