This project automates API testing for the Simple Books API using Postman and JavaScript. The API automation is implemented to validate book listings, order management, and client registration processes, leveraging Postman’s powerful scripting capabilities in conjunction with JavaScript for dynamic API test cases. This project ensures robust testing of all critical API endpoints through automated workflows.
- Overview
- Technologies Used
- API Endpoints Covered
- Project Structure
- Setup Instructions
- Running the Tests
- Postman Reports
- SEO Keywords
- Contributing
- License
- Postman: API testing and automation platform.
- JavaScript: For scripting logic within Postman.
- Newman: Command-line tool to run Postman collections.
- Postman Collection Runner: To execute requests in bulk and validate API responses.
- JSON: For managing test data and response validation.
- Environment Variables: Used in Postman to handle dynamic data (like tokens, order IDs).
- Endpoint:
GET /status
- Description: Verifies the health status of the API.
- Endpoint:
GET /books
- Query Parameters:
type
: fiction or non-fiction (optional)limit
: number between 1 and 20 (optional)
- Description: Retrieves a list of books with optional filters.
- Endpoint:
GET /books/:bookId
- Description: Retrieves details of a specific book by its ID.
- Endpoint:
POST /orders
- Description: Submits a new order for a book.
- Authentication: Requires a Bearer token.
- Request Body:
{ "bookId": 1, "customerName": "John" }
- Endpoint:
GET /orders
- Description: Lists all orders placed by the API client.
- Authentication: Requires a Bearer token.
- Endpoint:
GET /orders/:orderId
- Description: Retrieves details for a specific order.
- Authentication: Requires a Bearer token.
- Endpoint:
PATCH /orders/:orderId
- Description: Updates the customer name of an existing order.
- Authentication: Requires a Bearer token.
- Request Body:
{ "customerName": "John" }
- Endpoint:
DELETE /orders/:orderId
- Description: Deletes an existing order.
- Authentication: Requires a Bearer token.
- Endpoint:
POST /api-clients
- Description: Registers a new API client to interact with the system.
- Request Body:
{ "clientName": "Postman", "clientEmail": "[email protected]" }
postman/
├── collections/
│ └── collections\SimpleBooksAPIWithPostmanJavaScript.postman_collection.json # Postman collection file containing all API requests
├── scripts/
│ └── pre-request.js # JavaScript for dynamic test data generation and token management
│ └── test-scripts.js # JavaScript assertions for validating API responses
- Collections: The
SimpleBooksAPI
collection file contains all the API requests, grouped by endpoints (e.g., Books, Orders). - Environment: The environment file includes variables like
base_url
,token
, and dynamic data for managing API sessions. - Scripts: JavaScript files define dynamic behaviors and test logic for validation purposes.
- Postman: Download and install Postman.
- Newman: Install Newman globally if you plan to run the collection via the command line:
npm install -g newman
-
Clone the Repository:
git clone https://github.com/MohamedSci/SimpleBooksAPIWithPostmanJavaScript.git cd SimpleBooksAPIWithPostmanJavaScript
-
Import Collection:
- Open Postman, click on Import, and choose the
collections\SimpleBooksAPIWithPostmanJavaScript.postman_collection.json
file from thepostman/collections/
directory.
- Open Postman, click on Import, and choose the
-
Set API Token:
- In the environment, replace the placeholder
{{token}}
with your actual Bearer token obtained via the/api-clients
endpoint.
- In the environment, replace the placeholder
- Open Postman and navigate to the Collection Runner.
- Select the SimpleBooksAPI collection.
- Choose the SimpleBooksAPI Environment.
- Click Run to execute all the requests and view the results in Postman.
To run the collection via the command line using Newman, execute:
newman run collections\SimpleBooksAPIWithPostmanJavaScript.postman_collection.json -r json,cli --reporter-json-export result.json
Newman supports generating detailed HTML and JSON reports for the executed test cases. To generate an HTML report, run:
newman run collections\SimpleBooksAPIWithPostmanJavaScript.postman_collection.json -r json,html,cli --reporter-json-export result.json --reporter-html-export newman-report.html
This will generate a newman-report.html
file containing the execution summary, request details, and pass/fail results for each test case.
- Postman API automation
- JavaScript API testing
- API testing with Postman
- Postman automation framework
- Simple Books API automation
- API automation tutorial
- REST API testing in Postman
- Newman Postman collection runner
- JavaScript dynamic API tests
- Automated API validation with Postman
We welcome contributions! To contribute to this project:
- Fork the repository
- Create a new feature branch (
git checkout -b feature/your-feature
) - Commit your changes (
git commit -m 'Add new feature'
) - Push the branch (
git push origin feature/your-feature
) - Open a Pull Request for review
This project is licensed under the Apache 2.0 License. See the LICENSE file for more details.
If you enjoy this content and want to support me, feel free to buy me a coffee
Happy testing with Postman and JavaScript! 🚀