API Testing
API Testing
API Testing
1
Click to edit Master title style
Introduction
A P I & A P I Te s t i n g
2 2
Click to edit Master
Introduction - API title style
3 3
Click to edit Master title style
4 4
Click to edit
Working Master title style
of API
5 5
Click to edit Master title style
Types of APIs
6 6
ClickTypes
API to edit Master title style
1. Web APIs: These are APIs that are accessed over the internet through HTTP
protocols. They enable communication between web servers and clients.
2. RESTful APIs: Representational State Transfer (REST) APIs adhere to
specific architectural principles and are widely used in web services.
3. SOAP APIs: Simple Object Access Protocol (SOAP) APIs use XML
messaging and are primarily used in enterprise-level applications.
4. Library-based APIs: These APIs are provided by libraries and are meant to
be used within the same programming language.
5. Hardware APIs: Enable interaction with hardware devices and components.
7 7
Click to edit Master title style
Components of an API
8 8
ClickRequest
API to edit Components
Master title style
Any REST request includes four essential parts: an HTTP method, an endpoint, headers, and a
body.
• An HTTP method describes what is to be done with a resource. There are four basic methods
also named CRUD operations:
POST to Create a resource,
GET to Retrieve a resource,
PUT to Update a resource,
DELETE to Delete a resource.
• Headers store information relevant to both the client and server. Mainly, headers provide
authentication data — such as an API key, the name or IP address of the computer where the
server is installed, and the information about the response format.
• A body is used to convey additional information to the server. For instance, it may be a piece
of data you want to add or replace.
• An endpoint contains a Uniform Resource Identifier (URI) indicating where and how to find
the resource on the Internet. The most common type of URI is a Unique Resource
Location (URL), serving as a complete web address.
9 9
ClickResponse
API to edit Master title style
Components
• Any REST Response includes three essential parts: status code, Response Header, and
Response Body
• Status code informs the client if the action was performed correctly or not on the requested
resource. It's a number with three digits (between 100 and 599) with a name, like 200 Success,
or 404 Not Found. There are many status codes grouped into five main categories:
informational responses (1xx), successes (2xx), redirections (3xx), client errors (4xx), and
server errors (5xx).
• The Response Header contains the information about the content that is being returned in
response together with data about the Server that sent it.
• The response body contains the requested information in the format specified by the Accept
field in the request header. For JSON, the body is typically an object or an array of objects.
1010
Click to edit Master title style
1111
Click to
HTTP edit Master
methods titlecodes
& Status style
1xx (100 –
GET Retrieves the information at a particular URL. 1 The response is informational.
199)
1212
Click to edit Master title style
Benefits of API
1313
ClickBenefits
API to edit Master title style
1. Interoperability: APIs enable different applications to work together, even if they are built
using different technologies or languages.
2. Modularity: APIs allow developers to build complex systems by integrating smaller,
specialized components.
3. Rapid Development: Using pre-built APIs saves time and effort in creating functionalities
from scratch.
4. Scalability: APIs facilitate the scaling of applications by decoupling different modules.
5. Third-Party Integration: APIs enable easy integration with third-party services, expanding
the functionality of applications.
1414
Click to edit Master title style
1515
ClickCases
Use to edit Master title style
1. Social Media Integration: APIs are used to integrate social media platforms into applications,
allowing users to log in or share content seamlessly.
2. Payment Gateways: APIs enable secure and quick payment processing within applications.
3. Maps and Geolocation: APIs like Google Maps API allow integration of maps and
geolocation services into apps.
4. Weather Data: Applications can access weather data from various providers using APIs to
display real-time forecasts.
5. E-commerce Integrations: APIs facilitate interactions between e-commerce platforms and
inventory management systems.
1616
Click to edit Master title style
Testing Scenarios
Examples
API testing scenarios for https://reqres.in/
1717
Click to edit Master title style
Examples
User Registration:
• Test the user registration endpoint (POST /api/register) with valid user data to ensure it returns a successful
response (HTTP 200) and provides the user with an authentication token.
• Verify that the API returns appropriate error responses (e.g., HTTP 400 Bad Request) when invalid or
incomplete user data is provided.
User Login:
• Test the user login endpoint (POST /api/login) with valid credentials to ensure it returns a successful
response (HTTP 200) and provides the user with an authentication token.
• Verify that the API returns appropriate error responses (e.g., HTTP 401 Unauthorized) when invalid
credentials are provided.
Create Resource:
• Test the endpoint to create a resource (POST /api/resource) with valid data to ensure it returns a successful
response (HTTP 201 Created) and creates the resource.
• Verify that the API returns appropriate error responses (e.g., HTTP 400 Bad Request) for invalid resource data.
Update Resource:
• Test the endpoint to update a resource (PUT /api/resource/{id}) with valid data to ensure it returns a successful
response (HTTP 200) and updates the resource.
• Verify that the API returns appropriate error responses (e.g., HTTP 404 Not Found) for invalid resource IDs. 1919
Delete Resource:
Click to edit Master title style
• Test the endpoint to delete a resource (DELETE /api/resource/{id}) with a valid resource ID to ensure it returns
a successful response (HTTP 204 No Content) and deletes the resource.
• Verify that the API returns a 404 Not Found response for non-existent resource IDs.
Pagination:
• Test endpoints that support pagination (e.g., /api/users?page=2&per_page=3) to ensure they return the correct
number of results per page and handle page navigation correctly.
Error Handling:
• Test the API with invalid routes to verify that it returns appropriate error responses (e.g., HTTP 404 Not
Found).
• Verify that the API returns detailed error messages without exposing sensitive information. 2020