Using the Postman Collection
How to Use the API β Using the Postman Collection
This section shows how to leverage the provided Postman collection to interact with your Library REST API. The collection includes ready-made requests for all CRUD operations, authentication, and user registration.
Importing the Collection π₯
- Open Postman.
- Click Import β Upload Files.
- Select
PYTHON/postman-collections/Python Rest API.postman_collection.json.
This collection defines endpoints such as GET /books, POST /book/<name>, POST /auth, and more .
Configuring the Environment βοΈ
- In Postman, create or select an Environment.
- Add a variable
urlwith valuehttp://localhost:5000(or your API base URL). - Ensure the collectionβs requests use
{{url}}as the base.
{{url}} β http://localhost:5000
Bootstrapping Authentication π
- Register a new user
- Endpoint:
POST {{url}}/register - Body (raw JSON):
{
"username": "sapan",
"password": "sapan1234"
}
- Obtain a JWT token
- Endpoint:
POST {{url}}/auth - Body (raw JSON):
{
"username": "sapan",
"password": "sapan1234"
}
- The collectionβs Tests script automatically saves
access_tokeninto thejwt_tokenglobal variable:
pm.test("JWT Token Not Empty", function () {
var jsonData = pm.response.json();
pm.globals.set("jwt_token", jsonData.access_token);
});
Running Book & Store Requests π
Once {{jwt_token}} is set, you can execute protected endpoints. The table below summarizes each request:
| Request | Method | Auth Header | Body Example | Description |
|---|---|---|---|---|
| List all books | GET | None | β | Retrieves all books |
| Get book by title | GET | Authorization: JWT {{jwt_token}} |
β | Fetches one book by title |
| Create a book | POST | Authorization: JWT {{jwt_token}}Content-Type: application/json |
{ "price": 200, "store_id": 2, "author": "sapan", "isbn": "WER3455", "release_date": "2020-12-12"} | Adds a new book |
| Update a book | PUT | β | β | Modifies existing book or creates it |
| Delete a book | DELETE | β | β | Removes a book by title |
| Create a store | POST | Authorization: JWT {{jwt_token}} |
β | Adds a new store |
| Delete a store | DELETE | β | β | Removes a store by name |
| List all stores | GET | None | β | Retrieves all stores |
Quick Tips
Note: Protected endpoints enforce JWT validation via
@jwt_required()inresources/book.pyandresources/store.py.
- Refresh Token: Re-run
/authwhenever the token expires. - Environment Cleanup: Delete
jwt_tokenglobal when switching users. - Debugging: Check the Console in Postman for raw request/responses.
Enjoy exploring your Library API through Postman!