CN
By Piotr Jura·
April 29, 2023
·Postman Basics: Guide for API Testing
Learn Postman fundamentals for API testing. Ideal for beginners in API and web development.
Introduction
Postman is a popular HTTP client for API testing. This guide covers Postman basics for developers of all levels.
Download PostmanMaking Your First Request
- Open Postman and create a new tab.
- Select an HTTP Method.
- Enter the API Endpoint URL.
- Click 'Send' to execute.
Example: GET Request
- Select
GETmethod. - Enter
https://api.example.com/users. - Click 'Send'.
- Review the response.
HTTP Methods and Status Codes
Common Methods
GET: Retrieve dataPOST: Submit new dataPUT: Update existing dataDELETE: Remove data
Status Codes
200 OK: Successful201 Created: Resource created400 Bad Request: Client error401 Unauthorized: Authentication required404 Not Found: Resource not found500 Internal Server Error: Server error
Headers
Key headers:
Content-Type: Media type of resourceAuthorization: Authentication credentialsAccept: Acceptable media typesUser-Agent: Client software identifier
Query Parameters
Add parameters via the 'Params' button next to the URL bar.
Example: https://api.example.com/users?role=admin
Workspaces, Environments, and Collections
Workspaces
- Personal: Individual projects
- Team: Collaborative projects
Environments
Define variables for different setups (development, staging, production).
Collections
Group related API requests for organization and sharing.
Sharing
Exporting
- Right-click on collection/environment.
- Select 'Export'.
- Choose format and save.
Importing
- Click 'Import'.
- Upload or drag and drop file.
Automation with JavaScript
Use the Tests tab to automate tasks like token extraction.
Example:
JavaScript
const json = JSON.parse(responseBody);
pm.environment.set("TOKEN", json.token);