Python - 301 - Flask
  • 00 - Appealing API's
  • 01- A Smooth Start
  • 02 - Chief Configuration
  • 03 - Example Endpoint and an Adornable App
  • 04 - Modeling the Models
  • 05 - Scheming Schemas
  • 06 - Making Migrations
  • 07 - Uniformed Users
  • 08 - Alarming Authentication
  • 09 - Account Actions
  • 10 - Postman Prevalence and Examining Endpoints
  • 11 - Blog Post Blogging
Powered by GitBook
On this page
  • Welcome to Postman
  • Installing Postman
  • Testing Endpoints
  • Sending User Requests
  • Create User
  • Login
  • Get Me
  • Update Me
  • Get All Users
  • Delete User

Was this helpful?

10 - Postman Prevalence and Examining Endpoints

In this module we will be using a new tool that will allow us to send requests and review the responses easily

Previous09 - Account ActionsNext11 - Blog Post Blogging

Last updated 6 years ago

Was this helpful?

Welcome to Postman

Postman is a desktop application designed to send and store HTTP requests. It is EXTREMELY useful for API development as it comes with every HTTP option (verb) available. Normally, a browser will only perform GET requests unless we send a form, which will then send a POST request. However, we don't have anything to click to send these requests. That's why we need postman

Installing Postman

  • Head over to and click the big orange download button

  • Then, run the installer when it finishes downloading and walk through the installation wizard

  • If postman does not start afterwards, use your operating system's search feature to launch Postman

Testing Endpoints

To test an endpoint we need to run our app. Make sure your environment variables are setup (using the steps in 02 - Chief Configuration) and your virtual environment is activated. Then run the following command from your projects root directory

python run.py

If everything goes smoothly you should see the following snippet

Sending User Requests

Let's send a request to postman to get oriented. Open up postman and you should see the following layout

1 - This is the request type 2 - This is the url to the request

The params | authorization | headers | body tabs are used to choose where in the request data will go in the form of a key-value pair

Create User

This request is pretty simple, Change the request type to POST (section 1 in image above), Then add the following url to the url box

http://localhost:5000/api/v1/users/

This is the endpoint for our user create function. All POST requests will be routed to that function because of the way we decorated it with user_view.route().

Now we need to define the body of the request. Remember that the User contains email, password, and name attributes. We should probably give this information with the registration. This is how we fake a form, by sending it in the form of HTTP with Postman.

To add a body, click they body tab, then click the raw radio button, then click the text drop down menu, and click JSON(application/JSON)

Then add the following text into the text field underneath

{
  "email": "test@test.com",
  "password": "password",
  "name": "testuser"
}

When you hit the SEND button you should receive a token as a response from the API

{
  "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1NTM2OTUzNTEsImlhdCI6MTU1MzYwODk1MSwic3ViIjoyfQ.KZnSLs1wRtcGBCLiskr0YoQH7Ar2w5dQx_O5SoUnrb0"
}

Login

Now that we've created a user, we are going to try and login to the API. In other words we're going to use our other method of receiving a token, if we already have created a user

The Request Method will still be POST, but the URL will change to

http://localhost:5000/api/v1/users/login/

Change the body of the request to contain just the email and password of the previously created user

{
  "email": "test@test.com",
  "password": "password"
}

When you hit SEND, you should receive another token

{
  "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1NTM2OTU2NjUsImlhdCI6MTU1MzYwOTI2NSwic3ViIjoyfQ.EOMp7EjNtQKXqh2riiTUaJf25Ta4Id6A7Nf2FLnft00"
}

Get Me

The Get Me endpoint will return the users profile. We know which users profile to return because we pass the web token that contains the users account validation. Change the request to GET, and copy the token without the quotes.

Go into the Header tab and fill the following spaces

Hit SEND and we should see the following response

{
  "blogposts": [],
  "created_at": "2019-03-26T14:02:31.425562+00:00",
  "email": "test@test.com",
  "id": 2,
  "modified_at": "2019-03-26T14:02:31.425569+00:00",
  "name": "testuser",
  "password": "$2b$10$nuBH6BHCMaXQLU.8DeXiAugMwVSPVw7fH4EnnxtjpjrBjznoShB4y"
}

Update Me

Change the request method to PUT, we are still using the same URL and token, and add the following in the body field

{
  "name": "test update"
}

We only need to specify the field we want to update

Hit SEND and you should see the following response

{
    "blogposts": [],
    "created_at": "2019-03-26T14:02:31.425562+00:00",
    "email": "test@test.com",
    "id": 2,
    "modified_at": "2019-03-27T14:00:04.370685+00:00",
    "name": "test update",  // <- This has changed
    "password": "$2b$10$nuBH6BHCMaXQLU.8DeXiAugMwVSPVw7fH4EnnxtjpjrBjznoShB4y"
}

Get All Users

Change the request method back to GET and change the URL to http://localhost/api/v1/users/

Hit SEND and you should see an array of users. In our case we only have one, but it will still be in a list format

[
  {
    "blogposts": [],
    "created_at": "2019-03-26T14:02:31.425562+00:00",
    "email": "test@test.com",
    "id": 2,
    "modified_at": "2019-03-27T14:00:04.370685+00:00",
    "name": "test update",
    "password": "$2b$10$nuBH6BHCMaXQLU.8DeXiAugMwVSPVw7fH4EnnxtjpjrBjznoShB4y"
  }
]

Delete User

Now we need to test the user DELETE endpoint. Change the request to DELETE, and change the URL to http://localhost:5000/api/v1/users/me. We don't need a body for this request so just hit SEND. We should see a 204 No Content status code just above and to the right of the response field

https://www.getpostman.com/downloads/
The output of run.py
Paste the copied token into the value field for api-token