API (Application Programming Interface)
An API is a mechanism that enables two applications to communicate with each other. On
the client side, we send data requests through the API, and on the server side, we receive
responses. APIs facilitate this entire process.
Example:
Uber does not have direct access to Google Maps. Instead, it sends a request to Google Maps'
APIs, which then respond by displaying the map within the Uber app.
Types of APIs:
- SOAP (Simple Object Access Protocol)
- REST (Representational State Transfer)
SOAP:
SOAP uses XML to transfer data in its message format.
REST:
REST is an architectural pattern that generally transfers data in JSON format. It uses HTTP
methods:
- GET: Retrieve data
- POST: Create a new resource
- PUT: Create or replace a resource
- DELETE: Remove a resource
- PATCH: Partially modify a resource
HTTP Methods:
POST:
- Used to create a new resource.
- Sending the same request multiple times creates multiple records.
PUT:
- Used to create or replace a resource.
- The same request does not create duplicates.
- If updating a candidate's name or email, all parameters must be passed; otherwise,
existing data gets replaced.
DELETE:
- Used to remove a resource.
PATCH:
- Used for partial modification.
- Only the specific fields that need updating are passed as parameters.
Parameters:
A parameter (param) is a value passed in an API request to modify its behavior.
Types of Parameters:
1. Query Parameters (?key=value) – Used to filter results.
Example: GET [Link]
2. Path Parameters (/:value) – Used to specify a resource.
Example: GET [Link] (fetch user with ID 123).
Authorization:
Used to authenticate API requests and ensure security.
Headers:
Headers contain extra information sent with an API request (e.g., content type).
- Postman automatically adds Authorization details to Headers when set.
Body:
Used in POST/PUT requests to send data.
Environment:
Stores variables (like base URLs, tokens, etc.) for different testing setups.
Initial Value:
The default value of a variable, shared across devices if synced.
Current Value:
A temporary value only visible on your local machine.
Pre-Request & Post-Response:
Pre-Request Script:
Runs before sending a request (used for setting variables, authentication, etc.).
Post-Response (Tests Tab):
Runs after getting a response (used for validation, extracting values, etc.).
Status Codes:
- 200 – Successful request
- 201 – Successful request, and data created
- 204 – Empty response
- 400 – Bad request
- 401 – Unauthorized access
- 403 – Access denied
- 404 – Data not found
- 500 – Internal server error
- 501 – Service unavailable
- 502 – Bad gateway