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 βš™οΈ

  1. In Postman, create or select an Environment.
  2. Add a variable url with value http://localhost:5000 (or your API base URL).
  3. Ensure the collection’s requests use {{url}} as the base.
   {{url}} β†’ http://localhost:5000

Bootstrapping Authentication πŸ”

  1. Register a new user
  2. Endpoint: POST {{url}}/register
  3. Body (raw JSON):
     {
       "username": "sapan",
       "password": "sapan1234"
     }
  1. Obtain a JWT token
  2. Endpoint: POST {{url}}/auth
  3. Body (raw JSON):
     {
       "username": "sapan",
       "password": "sapan1234"
     }
  • The collection’s Tests script automatically saves access_token into the jwt_token global 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() in resources/book.py and resources/store.py .

  • Refresh Token: Re-run /auth whenever the token expires.
  • Environment Cleanup: Delete jwt_token global when switching users.
  • Debugging: Check the Console in Postman for raw request/responses.

Enjoy exploring your Library API through Postman!