Show Menu
Cheatography

Ready to publish? When your cheat sheet is complete and ready for the world to see, click the button below.

This is a draft cheat sheet. It is a work in progress and is not finished yet.

API Testing

API testing is the process of testing an Applic­ation Progra­mming Interface (API) to validate its functi­ona­lity, reliab­ility, security, and perfor­mance.
Instead of testing the User Interface (UI), API testing is performed at the applic­ation layer to verify how different applic­ations or systems commun­icate with each other by sending requests and receiving responses.
Postman is one of the most widely used API testing tools that allows testers and developers to send API requests and validate the responses without using the applic­ation's user interface. It supports testing REST and SOAP APIs and helps verify response status codes, response body, response time, authen­tic­ation, headers, and error handling.
Postman also allows requests to be organised into collec­tions, automated using JavaScript test scripts, and integrated into CI/CD pipelines using Newman.

Commonly used HTTP Methods

The commonly used HTTP methods are GET, POST, PUT, and DELETE.
GET is used to retrieve data from a server.
POST is used to create or add new data to the server.
PUT is used to update or replace an existing resource on the server.
DELETE is used to remove data or resources from the server.
Each method performs a different operation depending on the business requir­ement.

REST & SOAP

REST (Repre­sen­tat­ional State Transfer) and SOAP (Simple Object Access Protocol) are both used for commun­ication between Applic­ations, but they work differently.
REST is an Archit­ectural Style, whereas SOAP is a Protocol.
My unnder­staning is that
REST APIs commonly exchange data in JSON format over HTTP or HTTPS.
SOAP APIs use XML messages and follow strict rules for Security and Messaging.
REST APIs are commonly tested using Postman, Swagger, and Insomnia, while SOAP APIs are commonly tested using SoapUI and Postman.
REST is commonly used for Web Applic­ations, Mobile Applic­ations, and Micros­ervices because it is simple and fast.
SOAP is commonly used in Enterprise Applic­ations, such as Banking and Healthcare, where Security and Reliab­ility are important.

Enviro­nment

Enviro­nment: A set of key-value variables specific to an enviro­nment, such as Develo­pment, QA, Staging, or Production.
• Lets you switch between enviro­nments without manually changing the request URLs.
• Stores reusable values such as base URL, authen­tic­ation token, and user creden­tials.
Example:
base_url = https:­//d­ev.a­pi.com (Develo­pment)
base_url = https:­//p­rod.ap­i.com (Production)

Collection

Collec­tions allow multiple API requests to be organised into a single reusable group.
e.g., all requests for the Worker Screening API
 

How to perform API Testing

In API testing, we send a request to the API using known input data and then analyse the response returned by the server.
○ My role during API testing is to verify that the API behaves correctly and returns the expected results.
○ To address this, I verify the accuracy of the response data, HTTP status code, response time, error codes returned by the API, authen­tic­ation and author­ization behaviour, non-fu­nct­ional aspects such as * perfor­mance and security.
○ Once I send a request to an endpoint in Postman and click the Send button, I receive the response in the response body together with the HTTP status code.
○ There are several ways to verify that the returned data is correct.
--The simplest method is checking whether the API returns the expected status code.
--Another method is writing assertions.
--I commonly create assertions to validate the response time, status code, status code descri­ption, response type, response headers, and specific values or strings within the response body.
Postman also provides many built-in snippets using the Chai JavaScript library. These snippets allow me to quickly validate status codes, verify that the response contains expected text, or compare the response body against expected values.

HTTP Response Status Codes

200 OK
Request succes­sful.
201 Created
Resource created succes­sfully.
400 Bad Request
Invalid request or input data.
401 Unauth­orized
Missing, invalid, or expired authen­tic­ation token.
403 Forbidden
Authen­ticated but permission denied.
404 Not Found
Resource or endpoint not found.
500 Internal Server Error
Unexpected server error.
503 Service Unavai­lable
Server tempor­arily unavai­lable.

Positive and Negative API testing

Positive Testing verifies that an API behaves correctly when valid data is provided.
Negative Testing verifies that the API handles invalid requests correctly without crashing or exposing unexpected behaviour.
My role while performing API Testing is to ensure both Positive and Negative Scenarios are fully covered.
To address this, I execute requests using valid input to confirm successful processing and expected responses. I also test missing mandatory fields, invalid data types, incorrect parameters, expired authen­tic­ation tokens, unsupp­orted HTTP methods, and malformed payloads.
For every scenario, I validate the returned HTTP Status Code, Response Body, and Error Messages.
As a result, Positive and Negative Testing help ensure the API is both functional and resilient.

Can a POST request create a resource?

Yes.
POST is primarily used to create new resources on the Server.
My role while testing POST APIs is to verify that the resource is succes­sfully created and that the API returns the correct Response.
To address this, I validate the Request Payload, execute the API, verify the HTTP Status Code, confirm the Response Body, and check that the newly created data exists within the Applic­ation or Database, where applicable.
As a result, I can confirm that the API succes­sfully creates new resources and behaves according to the Business Requir­ements.

Path paramerter & Query Parameter

Path Parameter: A value included in the API URL path to identify a specific resource.
Example: /users/123

Query Parameter: A value added after the ? in the URL to filter, search, sort, or control the response.
Example: /users­?st­atu­s=a­ctive

Payload

A Payload is the actual data sent from the Client to the Server as part of an API Request.
My role while testing APIs is to ensure that the Payload contains the correct inform­ation before sending the request.
To address this, I validate the Payload Structure, Field Names, Mandatory Fields, Data Types, and Business Values before executing the request.
I also verify that the API processes the Payload correctly and returns the expected Response.
As a result, I can confirm that the API correctly accepts, validates, and processes the incoming data.
 

Components of HTTP request

An HTTP Request consists of several important compon­ents.
1. HTTP Request Method, such as GET, POST, PUT, PATCH, or DELETE, which defines the action to be performed.
2. Uniform Resource Identifier (URI), which represents the endpoint where the API is hosted.
3. Resources and Parameters, including Path Parameters and Query Parameters, which are used to pass inform­ation to the API.
4. Request Header, which carries metadata as key-value pairs, such as Conten­t-Type, Author­ization tokens, Accept, and other request inform­ation.
5. Request Body, also known as the Payload, which contains the data being sent to the server. It is commonly used with POST, PUT, and PATCH requests.
--Toge­ther, these components make up a complete HTTP Request.

Challenges in API Testing?

Some of the common challenges involved in API testing include API docume­nta­tion, database access, and author­ization.
--API docume­ntation is important because incomplete or outdated docume­ntation can make it --diff­icult to understand the API behaviour and expected responses.
--Obtaining access to the database when backend data validation is required.
--Author­ization can also be challe­nging because APIs often require authen­tic­ation tokens, creden­tials, or different user roles before requests can be executed succes­sfully.

Authen­­ti­c­ation and Author­­iz­ation

Authen­tic­ation and Author­ization are both used to secure APIs, but they serve different purposes.
Authentication = Who are you? (Identity Verifi­cation)
Authorization = What can you access? (Permi­ssion Verifi­cation)
Authen­tic­ation verifies the identity of the user or applic­ation. It answers the question, "Who are you?"
Common authen­tic­ation methods include Bearer Tokens, OAuth, Basic Authen­tic­ation, and API Keys.
Author­ization determines what an authen­ticated user is allowed to access or perform. It answers the question, "What are you allowed to do?"
It checks the user's roles, permis­sions, or access rights before allowing access to a resource.
Example:
401 Unauth­orized → Authen­tic­ation failed (invalid or missing token).
403 Forbidden → Authen­tic­ation succeeded, but the user doesn't have permis­sion.

Authen­­ti­c­ation technique

Some of the commonly used Authen­tic­ation techniques include
Session or Cookie­-Based Authen­tic­ation,
Basic Authen­tic­ation,
Digest Authen­tic­ation, and
OAuth.
Session or Cookie­-Based Authen­tic­ation is commonly used in tradit­ional Web Applic­ations.
Basic Authen­tic­ation uses a Username and Password encoded within the Request.
Digest Authen­tic­ation is similar to Basic Authen­tic­ation but provides additional Security by encrypting the Creden­tials.
OAuth is widely used for modern Web Applic­ations because it provides secure Token-­Based Authen­tic­ation without exposing User Creden­tials.

Variables

Variables are used to store reusable values that can be referenced throughout a Postman Collection.
• Defined using double curly braces: {{variable_name}}
• Can be used in URLs, Headers, Request Body, and Scripts.

--Variables allow values to be stored and reused throughout API requests.
--My role while using variables is to eliminate hardcoded values and improve mainta­ina­bility.
--To address this, I use Global Variables, Collection Variables, Enviro­nment Variables, Local Variables, and Data Variables depending on the testing scenario.
--For example, instead of hardcoding the Base URL in every request, I store it as an Enviro­nment Variable. If the enviro­nment changes from Develo­pment to UAT, I simply switch the Enviro­nment without modifying each request individually.
--As a result, variables make API requests easier to maintain, more reusable, and less prone to manual errors.

Different types of Variables

Global Variables are accessible across every Collection and Enviro­nment within the workspace.
Enviro­nment Variables are available only within the currently selected Enviro­nment, such as Develo­pment, QA, or UAT.
Collection Variables are available only within a specific Collection, regardless of which Enviro­nment is selected.
Postman follows a Variable Precedence order when resolving variables. The priority from highest to lowest is Local VariablesData VariablesEnviro­nment VariablesCollection VariablesGlobal Variables.
As a result, unders­tanding Variable Scope helps prevent conflicts, improves mainta­ina­bility, and keeps API requests organised and reusable.

Pre-re­­quest Script

Pre-re­­quest Script: A JavaScript script that runs before an API request is sent.
They are written in the Pre-re­­quest Script tab.
Commonly used for:
Setting dynamic variables, such as timestamps or generated tokens.
○ Generating authen­­ti­c­ation tokens before calling an API endpoint.
Chaining data from a previous request.
Preparing request data before execution.
Example: pm.env­­ir­o­n­me­­nt.s­­e­t­(­"­ti­­mes­­ta­m­p­", Date.n­­ow());