In previous article, I have mentioned ASP.NET Core Interview questions and answers but now in this article, I have mentioned about widely use api testing application Postman interview questions with answers.

What is Postman?

Postman is an API platform for building and using APIs. Postman simplifies each step of the API lifecycle and streamlines collaboration so you can create better APIs faster and simply test output of API using Postman, without calling it from any front-end UI of any type of application.

API Test suites can be quickly designed using Postman, and also it can store test information to be used in other tests.

Why use Postman?

It makes API testing much easier and faster, and hence development of API is faster as Postman is an API client that makes it easy for developers to create, share, test and document APIs.

This is done by allowing users to create and save simple and complex HTTP/s requests, as well as read their responses. As a result, we get more efficient and less tedious work.

What is a collection in Postman?

'Collections' allow you to group together several APIs that might be related, or perhaps should be executed in a certain sequence.

Postman Collections are a group of saved requests. Every request you send in Postman appears under the History tab of the sidebar. On a small scale, reusing requests through the history section is convenient. As your Postman usage grows, it can be time-consuming to find a particular request in your history.

Instead of scrolling through your history section, you can create collection and save all your requests as a group for easier access.

What are different type of variables in Postman?

Postman supports variables at different scopes, allowing you to tailor your processing to a variety of development, testing, and collaboration tasks.

In order from broadest to narrowest, these scopes are: global, collection, environment, data, and local.

Global variables enable you to access data between collections, requests, test scripts, and environments. Global variables are available throughout a workspace. Since global variables have the broadest scope available in Postman, they're well-suited for testing and prototyping. In later development phases, use more specific scopes.

Collection variables are available throughout the requests in a collection and are independent of environments. Collection variables don't change based on the selected environment. Collection variables are suitable if you're using a single environment, for example for auth or URL details.
Environment variables enable you to scope your work to different environments, for example local development versus testing or production. One environment can be active at a time. If you have a single environment, using collection variables can be more efficient, but environments enable you to specify role-based access levels.

Data variables come from external CSV and JSON files to define data sets you can use when running collections with Newman or the Collection Runner. Data variables have current values, which don't persist beyond request or collection runs.

Local variables are temporary variables that are accessed in your request scripts. Local variable values are scoped to a single request or collection run, and are no longer available when the run is complete.

Local variables are suitable if you need a value to override all other variable scopes but don't want the value to persist once execution has ended.

Which are the various authorization methods provided by Postman?

Postman provides the following API request authorization options:

  • API Key
  • Oauth 1.0
  • Oauth 2.0
  • Bearer Token
  • Basic auth
  • Digest auth
  • Hawk Authentication
  • AWS Signature
  • NTLM Authentication

What is payload in Postman?

The Payload of an API Module is the body of your request and response message. It contains the data that you send to the server when you make an API request.

You can send and receive Payload in different formats, for example in JSON or XML.

What are the most commonly used HTTP methods supported by REST?

GET is only used to request data from a specified resource. Get requests can be cached and bookmarked. It remains in the browser history and haS length restrictions. GET requests should never be used when dealing with sensitive data.

POST is used to send data to a server to create/update a resource. POST requests are never cached and bookmarked and do not remain in the browser history.

PUT replaces all current representations of the target resource with the request payload.

DELETE removes the specified resource.

What is a Pre-request script in Postman?

Pre-request scripts in Postman to execute JavaScript before a request runs.

Scripts in the Pre-request Script tab for a request, collection, or folder, you can carry out pre-processing such as setting variable values, parameters, headers, and body data.

How do you add a header to every request in Postman in the pre-request script?

To add a header to every request, go to your collection, right-click it, select Edit, and go to the Pre-request Scripts tab, where you can add the snippet

pm.request.headers.add({
  key: 'X-HEADER-TEST',
  value: '1'
});

What is the Postman execution order for a collection?

postman-interview-questions.jpg

For every request in a collection, scripts will execute in the following order:

  1. A pre-request script associated with a collection will run prior to every request in the collection.
  2. A pre-request script associated with a folder will run prior to every request in the folder.
  3. A test script associated with a collection will run after every request in the collection.
  4. A test script associated with a folder will run after request in the folder.

How do you set a dynamic variable in Postman?

Postman uses the faker library to generate dummy data. You can generate random names, addresses, email addresses, and much more.

A dynamic variable name starts with '$.' In the request URL section, a dynamic variable should be written in {{__}} format.

Let's say you have to pass an integer number from 1 to 5000, so for that, you need to add {{$randomInteger}}.

How do you debug your collection, pre-request, test scripts in Postman?

We can debug written scripts by using Pre-request Script or Tests tabs, and we can validate log messages using the Postman console.

For example:

  1. Open the Postman Console (CMD/CTRL + ALT + C).
  2. Under the Pre-request Script or Tests tabs of the Postman app, write an expression, like console.log("Log here").
  3. Click "Send"

When you send a request or run a collection of requests, your message will output to the Postman Console as a string or JavaScript object(s). If you’re familiar with the console.log() function in JavaScript, this is similar.

How to send a base64 image in postman?

You could find an online base64 image encoder. They encode an image to a string. The example of a raw body in JSON format in the POSTMAN:

"profile": { "first_name": "Hello",
 "last_name": "World",
 "photo": "iVBORwAAAYIIXX= //reduced data as it was too long"
}

How to handle a self-signed certificate with Postman?

You can handle this by disabling SSL certificate verification in Postman. Settings->SSL certificate verification

You may also like to read:

ASP.NET Core Interview questions and answers

AWS EC2 Interview Questions and answer

AWS S3 Interview questions and answers

XML Interview questions and Answers