Postman Collection – Importing the Collection
This section explains how to import and configure the provided Postman collection, Python Rest API, to exercise every endpoint of the demo RESTful API (built with Flask, Flask-RESTful, Flask-JWT, and SQLAlchemy). The collection includes requests for user registration, authentication, and full CRUD operations on books and stores, complete with tests that capture and reuse the JWT access token.
📑 Index
- Prerequisites
- Importing the Collection
- Configuring Environment Variables
- Exploring the Collection Structure
- Built-in Tests & Scripts
- Quick-Start Workflow
Prerequisites
- Postman (v7.0+) installed on your machine.
- The API running locally (default:
http://localhost:5000) or remotely. - Access to the JSON file:
postman-collections/Python Rest API.postman_collection.json.
Importing the Collection
- Open Postman.
- Click Import (top-left).
- Select File → Choose Files.
- Navigate to the repository and pick
postman-collections/Python Rest API.postman_collection.json - Click Open → Import.
Once imported, you’ll see a new collection named Python Rest API with all predefined requests.
{
"info": {
"_postman_id": "cc4b0006-42be-4ace-8ef4-5c7f79653d34",
"name": "Python Rest API",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [ … ]
}
Configuring Environment Variables
The collection relies on two variables:
| Variable | Description | Example Value |
|---|---|---|
| url | Base URL of your running API | http://localhost:5000 |
| jwt_token | JWT access token (populated by /auth test) |
— |
Setting Variables
-
Click the Environment dropdown (top-right) → Manage Environments.
-
Create a new environment (e.g., Python-API-Env).
-
Add two variables:
Key Initial Value Current Value urlhttp://localhost:5000jwt_token(leave blank) -
Save and select Python-API-Env.
All endpoints use {{url}} in their URLs; those requiring authentication append an Authorization header:
Authorization: JWT {{jwt_token}}
Exploring the Collection Structure
| Request Name | Method | Endpoint | Auth Required? | Body |
|---|---|---|---|---|
| Register User | POST | /register |
No | JSON |
| Authenticate (Auth) | POST | /auth |
No | JSON |
| List Stores | GET | /stores |
No | — |
| Create Store | POST | /store/:name |
Yes | — |
| Get Store | GET | /store/:name |
No | — |
| Delete Store | DELETE | /store/:name |
No | — |
| List Books | GET | /books |
No | — |
| Get Book | GET | /book/:title |
Yes | — |
| Create Book | POST | /book/:title |
Yes | JSON |
| Update Book | PUT | /book/:title |
No | JSON* |
| Delete Book | DELETE | /book/:title |
No | — |
* The Update Book request in this collection has no body by default; you can toggle Body → raw (JSON) and supply fields as needed.
Built-in Tests & Scripts
The Authenticate request (POST /auth) includes a test script that:
- Asserts the returned
access_tokenis not empty. - Stores the token into the
jwt_tokenglobal variable for subsequent requests.
pm.test("JWT Token Not Empty", function () {
var jsonData = pm.response.json();
pm.globals.set("jwt_token", jsonData.access_token);
});
This snippet is defined under the event → test section in the JSON:
Quick-Start Workflow
- Register a new user
- Authenticate to obtain a JWT
- Create stores and books (using the token)
- Query, update, and delete resources
Tip: Use Runner in Postman to execute all requests in sequence.
Happy Testing!