API Postman
API Postman
API testing can be performed manually or using automated testing tools. Some
common tasks that are performed during API testing include:
● Testing the functionality of the API to ensure it behaves as expected
● Verifying that the API returns the correct response for different input
values Checking for error handling and validation of input
Testing for security vulnerabilities
● Checking for performance and scalability of the API
● API testing is important because it ensures that the different components
of a system can communicate with each other correctly and that the
system can handle a large volume of requests.
The difference between an API and a web application is that an API allows two-way
communication and web applications are just a way for users to interact through a web
browser. A web application may have an API to complete the requests.
Types of APIs
There are three basic forms of API –
1. WEB APIs
A Web API also called Web Services is an extensively used API over the web and can be
easily accessed using the HTTP protocols. A Web application programming interface is
an open-source interface and can be used by a large number of clients through their
phones, tablets, or PCs.
2. LOCAL APIs
In this type of API, the programmers get the local middleware services. TAPI (Telephony
Application Programming Interface), and .NET are common examples of Local APIs.
3. PROGRAM APIs
It makes a remote program appear to be local by making use of RPCs (Remote Procedural
Calls). SOAP is a well-known example of this type of API.
Its main feature is that REST API is stateless, i.e., the servers do not save clients’ data
between requests.
● Open API
● Partner API
● Internal API
● Composite API
SOAP REST
SOAP (Simple Object
REST (Representational State
Access Protocol) is a
Transfer) is a set of guidelines
protocol with specific
(architectural style) offering
requirements like XML
flexible implementation
messaging
○ Postman variables work in the same way as that of the programming variables. These are
the symbols capable of taking various values. You can store the values in variables and can
use it throughout in requests, environments, collections, and scripts.
○ Variables in Postman increase the user's efficiency to work and decrease the errors.
○ Variable-Use {{url}}
Variable Scopes
Variable scope is the boundary within which these variables can be accessed and executed.
The following variable scopes are supported by Postman, which is used for different tasks.
The narrowest variable scope is Local, and then next is Data, Environment, Collection, and
the broadest one is Global.
In case, the variable name is the same, in two scopes with a different value, then the value
of the narrowest variable scope will be used while running the request. Let's say the name
of both local and global variables is My Variable. Then Postman will use a local variable
value to run the request, as a local variable is the narrowest variable scope.
○ Local Variables
These are temporary variables that will only function inside the environment they
were created in. When you change the environment, the variable will stop its access,
and an error will occur.
○ Collection Variables
These are independent of environments and are available for all the requests in a
collection.
○ Environment Variables
These are the most used variable scope in Postman. At a time, a single environment
can be active. They are bound to a specified environment used to execute the
request.
○ Global Variables
These are independent of environments and function outside the environment.
Users are not required to create an environment for global variables. Through global
variables, we can access data between collections, test scripts, requests, and
environments.
○ Data Variables
Data variables come from external CSV and JSON files to define data sets that you
can use while collections are running through Newman or the Collection Runner.
Passing Data With Your Request & Debugging
'Untitled request' is basically the default request title you are working on. The title depends
on the type of request method you are working on, as shown in the image below.
○ HTTP request
This option opens a drop-down list of all the HTTP request methods, as shown in the image
like GET, DELETE, PATCH, OPTIONS, LINK, POST, COPY, UNLOCK, PURGE, etc. In general, we
mostly use POST and GET. We will discuss these requests in later chapters.
This URL option is like any other browser URL. In this, we mention the link to where the
API will communicate with.
○ Params
This option is used to write the parameters of the request. These parameters include key
values and descriptions.
○ Authorization
The authorization process is required to access the APIs. This process verifies whether you
have permission from the server to access the data you want. We will discuss this as a
complete chapter later on.
○ Headers
An HTTP request header is the additional data that is required to send along with the
request. This header information is required for proper two-direction communication
between the client and the server.
○ Body
It lets you specify the data type that you need to send with a request. There are various
types of body data that you can send to match your API.
○ Pre-request script
These are written in JavaScript, and as the name suggests, these are executed before
sending the request. Generally, these scripts are for setting the environment and ensuring
that the request is running in the right environment.
○ Test scripts
It is executed during the request. It is also written in JavaScript. This helps you to ensure
that the API works as intended. Testing is important as it sets up checkpoints to verify
whether the response status is ok and retrieved data is as expected.
4. Response section
The API responses which are sent back from the server are shown in the response window.
These are generated after you send an API request to the server. As we have not sent any
request, so there is no response in our case.