Postman



GUID in Postman. In the last tutorial, we have discussed GUID in general and how it has affected the overall internet mechanism of saving the data into the database. It has proved to be a satisfying and revolutionizing solution to a problem that existed for some time. POSTMAN Introduction. POSTMAN is an API client used to develop, test, share and document APIs. It is used for backend testing where we enter the end-point URL, it sends the request to the server and receives the response back from the server. Postman: Sends direct GET, POST, PUT, DELETE etc. Request without checking what type of server is and getting the header Access-Control-Allow-Origin by using OPTIONS call to the server. Share Improve this answer. EASILY TRANSFER YOUR COLLECTIONS TO THE POSTMAN NATIVE APP When you sign in with the Postman account associated with Postman Chrome, your collections and data will automatically sync with the app. NEW FEATURES AVAILABLE IN THE NATIVE APPS Postman native apps include all of the functionality of Postman Chrome, and much, much more.

-->

Postman is a REST testing tool that provides key HTTP request functionalities in a desktop and plugin-based GUI. You can use it to craft HTTP requests and submit them to the Azure Digital Twins REST APIs.

Postman

This article describes how to configure the Postman REST client to interact with the Azure Digital Twins APIs, through the following steps:

  1. Use the Azure CLI to get a bearer token that you will use to make API requests in Postman.
  2. Set up a Postman collection and configure the Postman REST client to use your bearer token to authenticate. When setting up the collection, you can choose either of these options:
    1. Import a pre-built collection of Azure Digital Twins API requests.
    2. Create your own collection from scratch.
  3. Add requests to your configured collection and send them to the Azure Digital Twins APIs.

Azure Digital Twins has two sets of APIs that you can work with: data plane and control plane. For more about the difference between these API sets, see How-to: Use the Azure Digital Twins APIs and SDKs. This article contains information for both API sets.

Prerequisites

To proceed with using Postman to access the Azure Digital Twins APIs, you need to set up an Azure Digital Twins instance and download Postman. The rest of this section walks you through these steps.

Set up Azure Digital Twins instance

To work with Azure Digital Twins in this article, you first need to set up an Azure Digital Twins instance. You also need the required permissions for using it. If you already have an Azure Digital Twins instance set up, you can use it instead.

Otherwise, follow the instructions in Set up an instance and authentication. The instructions contain information to help you verify that you've completed each step successfully.

After you set up your instance, make a note of the following values. You'll need these values to connect to the instance later:

  • The instance's host name. You can find the host name in the Azure portal.
  • The Azure subscription that you used to create the instance. Either its name or its ID will work. You can find the subscription on your instance's Overview page in the Azure portal.

Download Postman

Next, download the desktop version of the Postman client. Navigate to www.getpostman.com/apps and follow the prompts to download the app.

Get bearer token

Now that you've set up Postman and your Azure Digital Twins instance, you'll need to get a bearer token that Postman requests can use to authorize against the Azure Digital Twins APIs.

There are several possible ways to obtain this token. This article uses the Azure CLI to sign into your Azure account and obtain a token that way.

If you have an Azure CLI installed locally, you can start a command prompt on your machine to run the following commands.Otherwise, you can open an Azure Cloud Shell window in your browser and run the commands there.

  1. First, make sure you're logged into Azure with the appropriate credentials, by running this command:

  2. Next, use the az account get-access-token command to get a bearer token with access to the Azure Digital Twins service. In this command, you'll pass in the resource ID for the Azure Digital Twins service endpoint, in order to get an access token that can access Azure Digital Twins resources.

    The required context for the token depends on which set of APIs you're using, so use the tabs below to select between data plane and control plane APIs.

    To get a token to use with the data plane APIs, use the following static value for the token context: 0b07f429-9f4b-4714-9392-cc5e8e80c8b0. This is the resource ID for the Azure Digital Twins service endpoint.

    Note

    If you need to access your Azure Digital Twins instance using a service principal or user account that belongs to a different Azure Active Directory tenant from the instance, you'll need to request a token from the Azure Digital Twins instance's 'home' tenant. For more information on this process, see How-to: Write app authentication code.

  3. Copy the value of accessToken in the result, and save it to use in the next section. This is your token value that you will provide to Postman to authorize your requests.

Postman Movie

Tip

This token is valid for at least five minutes and a maximum of 60 minutes. If you run out of time allotted for the current token, you can repeat the steps in this section to get a new one.

Next, you'll set up Postman to use this token to make API requests to Azure Digital Twins.

About Postman collections

Requests in Postman are saved in collections (groups of requests). When you create a collection to group your requests, you can apply common settings to many requests at once. This can greatly simplify authorization if you plan to create more than one request against the Azure Digital Twins APIs, as you only have to configure these details once for the entire collection.

When working with Azure Digital Twins, you can get started by importing a pre-built collection of all the Azure Digital Twins requests. You may want to do this if you're exploring the APIs and want to quickly set up a project with request examples.

Alternatively, you can also choose to start from scratch, by creating your own empty collection and populating it with individual requests that call only the APIs you need.

The following sections describe both of these processes. The rest of the article takes place in your local Postman application, so go ahead and open the Postman application on your computer now.

Import collection of Azure Digital Twins APIs

A quick way to get started with Azure Digital Twins in Postman is to import a pre-built collection of requests for the Azure Digital Twins APIs.

Download the collection file

The first step in importing the API set is to download a collection. Choose the tab below for your choice of data plane or control plane to see the pre-built collection options.

There are currently two Azure Digital Twins data plane collections available for you to choose from:

  • Azure Digital Twins Postman Collection: This collection provides a simple getting started experience for Azure Digital Twins in Postman. The requests include sample data, so you can run them with minimal edits required. Choose this collection if you want a digestible set of key API requests containing sample information.
    • To find the collection, navigate to the repo link and open the file named postman_collection.json.
  • Azure Digital Twins data plane Swagger: This repo contains the complete Swagger file for the Azure Digital Twins API set, which can be downloaded and imported to Postman as a collection. This will provide a comprehensive set of every API request, but with empty data bodies rather than sample data. Choose this collection if you want to have access to every API call and fill in all the data yourself.
    • To find the collection, navigate to the repo link and choose the folder for the latest spec version. From here, open the file called digitaltwins.json.

The collection currently available for control plane is the Azure Digital Twins control plane Swagger. This repo contains the complete Swagger file for the Azure Digital Twins API set, which can be downloaded and imported to Postman as a collection. This will provide a comprehensive set of every API request.

To find the collection, navigate to the repo link and choose the folder for the latest spec version. From here, open the file called digitaltwins.json.

Here's how to download your chosen collection to your machine so that you can import it into Postman.

  1. Use the links above to open the collection file in GitHub in your browser.
  2. Select the Raw button to open the raw text of the file.
  3. Copy the text from the window, and paste it into a new file on your machine.
  4. Save the file with a .json extension (the file name can be whatever you want, as long as you can remember it to find the file later).

Import the collection

Next, import the collection into Postman.

  1. From the main Postman window, select the Import button.

  2. In the Import window that follows, select Upload Files and navigate to the collection file on your machine that you created earlier. Select Open.

  3. Select the Import button to confirm.

The newly imported collection can now be seen from your main Postman view, in the Collections tab.

Next, continue on to the next section to add a bearer token to the collection for authorization and connect it to your Azure Digital twins instance.

Configure authorization

Next, edit the collection you've created to configure some access details. Highlight the collection you've created and select the View more actions icon to pull up a menu. Select Edit.

Follow these steps to add a bearer token to the collection for authorization. This is where you'll use the token value you gathered in the Get bearer token section in order to use it for all API requests in your collection.

Postman app
  1. In the edit dialog for your collection, make sure you're on the Authorization tab.

  2. Set the Type to OAuth 2.0, paste your access token into the Access Token box, and select Save.

Additional configuration

If you're making a data plane collection, help the collection connect easily to your Azure Digital Twins resources by setting some variables provided with the collections. When many requests in a collection require the same value (like the host name of your Azure Digital Twins instance), you can store the value in a variable that applies to every request in the collection. Both of the downloadable collections for Azure Digital Twins come with pre-created variables that you can set at the collection level.

  1. Still in the edit dialog for your collection, move to the Variables tab.

  2. Use your instance's host name from the Prerequisites section to set the CURRENT VALUE field of the relevant variable. Select Save.

  3. If your collection has additional variables, fill and save those values as well.

When you're finished with the above steps, you're done configuring the collection. You can close the editing tab for the collection if you want.

If you're making a control plane collection, you've done everything that you need to configure the collection. You can close the editing tab for the collection if you want, and proceed to the next section.

Explore requests

Next, explore the requests inside the Azure Digital Twins API collection. You can expand the collection to view the pre-created requests (sorted by category of operation).

Different requests require different information about your instance and its data. To see all the information required to craft a particular request, look up the request details in the Azure Digital Twins REST API reference documentation.

You can edit the details of a request in the Postman collection using these steps:

  1. Select it from the list to pull up its editable details.

  2. Fill in values for the variables listed in the Params tab under Path Variables.

  3. Provide any necessary Headers or Body details in the respective tabs.

Once all the required details are provided, you can run the request with the Send button.

You can also add your own requests to the collection, using the process described in the Add an individual request section below.

Create your own collection

Instead of importing the existing collection of all Azure Digital Twins APIs, you can also create your own collection from scratch. You can then populate it with individual requests using the Azure Digital Twins REST API reference documentation.

Create a Postman collection

  1. To create a collection, select the New button in the main postman window.

    Choose a type of Collection.

  2. This will open a tab for filling the details of the new collection. Select the Edit icon next to the collection's default name (New Collection) to replace it with your own choice of name.

Next, continue on to the next section to add a bearer token to the collection for authorization.

Configure authorization

Follow these steps to add a bearer token to the collection for authorization. This is where you'll use the token value you gathered in the Get bearer token section in order to use it for all API requests in your collection.

  1. Still in the edit dialog for your new collection, move to the Authorization tab.

  2. Set the Type to OAuth 2.0, paste your access token into the Access Token box, and select Save.

When you're finished with the above steps, you're done configuring the collection. You can close the edit tab for the new collection if you want.

The new collection can be seen from your main Postman view, in the Collections tab. Keyboard with thumbstick.

Add an individual request

Now that your collection is set up, you can add your own requests to the Azure Digital Twin APIs.

  1. To create a request, use the New button again.

    Choose a type of Request.

  2. This action opens the SAVE REQUEST window, where you can enter a name for your request, give it an optional description, and choose the collection that it's a part of. Fill in the details and save the request to the collection you created earlier.

You can now view your request under the collection, and select it to pull up its editable details.

Set request details

To make a Postman request to one of the Azure Digital Twins APIs, you'll need the URL of the API and information about what details it requires. You can find this information in the Azure Digital Twins REST API reference documentation.

To proceed with an example query, this article will use the Query API (and its reference documentation) to query for all the digital twins in an instance.

  1. Get the request URL and type from the reference documentation. For the Query API, this is currently POST https://digitaltwins-hostname/query?api-version=2020-10-31.

  2. In Postman, set the type for the request and enter the request URL, filling in placeholders in the URL as required. This is where you will use your instance's host name from the Prerequisites section.

  3. Check that the parameters shown for the request in the Params tab match those described in the reference documentation. For this request in Postman, the api-version parameter was automatically filled when the request URL was entered in the previous step. For the Query API, this is the only required parameter, so this step is done.

  4. In the Authorization tab, set the Type to Inherit auth from parent. This indicates that this request will use the authorization you set up earlier for the entire collection.

  5. Check that the headers shown for the request in the Headers tab match those described in the reference documentation. For this request, several headers have been automatically filled. For the Query API, none of the header options are required, so this step is done.

  6. Check that the body shown for the request in the Body tab matches the needs described in the reference documentation. For the Query API, a JSON body is required to provide the query text. Here is an example body for this request that queries for all the digital twins in the instance:

    For more information about crafting Azure Digital Twins queries, see How-to: Query the twin graph.

  7. Check the reference documentation for any other fields that may be required for your type of request. For the Query API, all requirements have now been met in the Postman request, so this step is done.

  8. Use the Send button to send your completed request.

After sending the request, the response details will appear in the Postman window below the request. You can view the response's status code and any body text.

You can also compare the response to the expected response data given in the reference documentation, to verify the result or learn more about any errors that arise.

Postman Game

Next steps

To learn more about the Digital Twins APIs, read How-to: Use the Azure Digital Twins APIs and SDKs, or view the reference documentation for the REST APIs.

APIs are integrated into many of the web services used today, allowing systems to send and communicate various pieces of information back and forth. As such, they are a powerful links between critical services. And as with any important part of a system, it is necessary to test them. Using third-party API testing solutions, or Postman, we can do both manual and automated tests. API stands for Application Programming Interface. It is a software-to-software interface. With APIs, applications converse with each other with no client intervention. But with thousands of APIs available, Postman comes into picture to create, test, share and manage these APIs making the API usage efficient and less tedious.

This article will help to understand Postman, collections, its prominent features, and how we can set up load tests for Postman collections and its integration with CI/CD pipelines with LoadView.

Explore our load testing solution or read below for steps on how to use Postman with LoadView

What is Postman?

Postman is a popular API client tool which makes it easier for development teams to create, share, test and document APIs. It provides a seamless user experience which helps in hitting API endpoints by quickly creating requests as per the API specification and dissecting the various response parameters like the status code, headers, and the actual response body itself. We can leverage these features for continuous and automated testing. It is used as a companion tool to develop, document and test against an API and provides a user interface to make REST APIs server requests and shows the response from servers.

Postman is an API development tool used in the software development life cycle:

  • API development
  • API testing
  • API documentation

Postman not only provides us with an environment to work with APIs, It can also be used to request web pages like a browser. Enter the URL in the address bar and hit send to see the HTML response. Postman can also help appending scripts before the user sends the request and after obtaining the response. We can store each request in a collection, which later can be used to run all requests in order.

What is API testing?

In API testing we use dedicated tools to send calls to the server hosting the API and retrieve the response. The objective of API testing is to confirm right execution and validating if the API is getting, saving or updating resources as intended.

If we know that the API is supposed to perform a particular action, like update data, fetch data, delete data, make a change in data, the tests should check the results of those actions. Does it behave the same way as it is supposed to be? What about when it is not supposed to happen? And are the results what you would expect it to be? API testing is typically black-box testing, but to the extent that we have access to the results of the API’s actions beforehand and we know the expected response which needs to be validated.

API Testing: Functional Testing vs. Load Testing

Like we briefly mentioned above, functional testing, or black-box testing, is primarily concerned with testing basic functions against a set of specifications and observing whether they work or not. Before APIs can be moved through the development cycle and tested further, it is important that the basic API functionalities are working. If developers move from functional testing to load testing without ensuring basic functions have been properly tested, it will throw off the load tests and results. The results from functional testing are simply observing whether something worked or not.

On the other hand, load testing is like functional testing, but the difference is that load testing sets to test how those functionalities stand up to large numbers of concurrent users, or load. The results of load testing include understanding how those API endpoints respond and perform under load.

Features of Postman

Import Requests

Postman provides an Import feature, where we can paste raw CURL text and convert it into a request formatted with details like Request URL, headers, request body, query parameters and Authorization tokens.

Postman

Multiple Protocol and Technology Support

Postman API client feature lets us send REST, SOAP, WSDL and GraphQL requests.

Write Test Cases

We can create test cases which run added APIs and can help in response validation with asserting JSON/XML responses and response code validations.

Collections

Postman helps us to create collections which helps to segregate APIs with folders Structure for different projects. It provides support to run Collection, which will eventually run all the APIs part of the collection.

JSON Schema validation

We can use JSON Schema to define the structure of their requests and responses. It helps to beautify and structure JSON making it easy to understand and read on Postman.

Use Environment and Dynamic Variables

We can create variables in Postman and based on different environments, the same variables can have different values mapped for the environment selected. This is helpful while we work with the same APIs, but multiple environments in the real world.

Convert API to Code

Postman allows the API request to be converted to code in all the prominent languages like JavaScript, Golang, Java, PHP, Python and many more.

Benefits of Postman

Automate Testing

Imvu poses. Postman let us automate API testing and integrate the collection with CI/CD pipelines. We can automate unit tests, integration tests, regression tests, and mock tests.

Platform and OS Compatible

Postman Rest Client

Postman is available on Mac, Windows, Linux and Chrome and supports all major operating systems.

Postman Test Reports

It provides a test report that helps us with tracking data through the request builder and we can generate HTML reports for the test runs.

Integrations

Postman provides support and can be easily integrated with all major developer tools like GitHub, Slack, Dropbox and GitLab.

Pricing

All the major functionalities of Postman are free of cost. We can get all the above benefits for free. There are also paid plans for Postman Pro and Postman Enterprise for small to large enterprises.

Alternatives to Postman

Swagger

Swagger is an open-source API specification, it is like WSDL for REST APIs, where you define the structure of the REST APIs (endpoints URLs, input/output models, authentication schema, etc.). The specification file is based on JSON and the file extension is either JSON or YAML. A few of the key highlights of Swagger are:

  • Open-source and free, however it can be hard to learn or find resources for issues.
  • Swagger represents APIs within the browser.
  • Can automatically generate documentation from building your services.

SoapUI

SoapUI allows users to quickly and easily test REST and SOAP APIs, as the tool was created specifically for testing APIs. SoapUI helps in testing complicated combinations of web services such as RESTful, SOAP, JSON and AMF. However, you need to utilize WSDL for testing web services. Additionally, to ingrate automation, there is a lot of scripting required, and for users who have not had that experience, it can become difficult and time consuming. A few of the key highlights of SoapUI are:

  • Point-and-click functionality helps to makes JSON and XML usability easier.
  • Load data from Excel, files, databases, etc.
  • Reuse your functional test cases as load tests.
  • Integrates with third-party API management platforms, supports REST, SOAP, JMS, and IoT, etc.

Integrate Postman Collection Testing into CI/CD Pipeline

Continuous Integration (CI) is a development practice which requires developers to regularly merge code into a shared repository. It involves the process of automating the build and testing of applications every time a new change gets committed to the source code. Continuous Development can be explained as a sequence of steps which are required to be performed in sequence to enable application to run on a specialized server and fulfill its use case of serving user requests.

Load Testing Postman Collections using LoadView

Whenever we test a back-end application, testing the functionality is a standard part of the process to ensure that things work as we had intended them to work. Now, that is all well and good, but not for the real world. Your applications will be utilized by many, if not hundreds or thousands of users at the same time, so we also need to carry out performance testing to see how well they hold up to that traffic. We need to benchmark and validate the application with each application change. As we have seen the overview of Postman, its features and how we can set up test strategy for API functional testing, we would need to understand tools which can help to stress test the application.

In cases where we are using Postman to test web API functionality and want to generate a load test from the API call collections we have, we can opt for a specialized load testing tool such as LoadView. LoadView provides real browser-based load testing for APIs, as well as web applications (external and internal), and websites and servers.

Test Setup

We will take a step-by-step look on how to set up a web application load test for a Postman collection.

LoadView Postman API Testing: Step 1

Before we even start, we would need to export the Postman Collection. We can choose the option to Get Public link and can easily import it to LoadView (Note: Make sure the Postman Collection uses local variables only since environment variables are not stored in the collection).

LoadView Postman API Testing: Step 2

Open the LoadView platform and select Create New load test.

LoadView Postman API Testing: Step 3

Here you will see the various load testing types that are available within LoadView – web apps, websites and APIs. For our use case, we will select the Postman Collection option to start API tests.

LoadView Postman API Testing: Step 4

A new window will open and here is where we will need to import the exported Postman collection and click Create Device.

LoadView Postman API Testing: Step 5

Once we have successfully created a device, we would see the Test Scenario screen, where we can set Load Type, which would differ based on the goal of our test.

  • Load Based Curve. This is to execute load tests with a known number of users and raise traffic after set warmup time.
  • Goal Based Curve. This test setup is used when we are looking for desired transactions per second for our specific API and want to scale to the desired rate slowly.
  • Dynamic based Curve. This set provides you to choose dynamic values in number of users, maximum users and test duration, and can be changed, in real-time, during the test.

LoadView Postman API Testing: Step 6

Once we have created a test scenario with a list of all APIs, we can now execute load and stress tests for our APIs. After successful completion of the load test run, you will be provided with reports, dashboards, and metrics that show how our API and systems performed under load.

Postman Collection Load test integration with Jenkins

As we have looked at how we can integrate and run Postman collection load tests using LoadView, we can add these tests as part of CI/CD to get regular feedback and performance results. LoadView also provides integration with Jenkins which helps stress test websites, web applications, and APIs with concurrent connections in real browsers from a fully managed cloud. Any new updates or additional features can also be load tested with the LoadView plugin for Jenkins.

Let us take a look at the steps used for the previously created Postman collection test scenario in LoadView and its integration with Jenkins.

Step 1. To integrate the tests with Jenkins, we would be using the same Postman test scenario created above.

Step 2. Create a unique UID. This is will be used as security token to integrate into Jenkins. Copy the Integration UID.

Postman App

Step 3. Test Scenario ID for our Postman collection can be found on the scenario setup page or on the test History page (Test Manager > the test actions menu > History).

LoadView Plugin in Jenkins

To configure the LoadView plugin, follow these steps:

  1. Log into your Jenkins account.
  2. In Jenkins, go to Credentials > Add Credentials > LoadView Security Token (UID). Configure and validate the credentials.
  • Kind. LoadView Security Token (UID).
  • Scope. Select Global.
  • ID. Leave the default or specify a unique ID.
  • Description. Specify a unique description to distinguish the credentials.
  • UID. Paste the load testing web API UID from your LoadView account. Once the UID has been added, click Validate UID to make sure Jenkins can access the LoadView API.
  1. Next, select a job and click Configure.

Postman Download For Windows

  1. Go to Build > Post-build Actions > Add post-build action > LoadView-Run load test scenario. Specify LoadView Stress Test settings for the build:
  • Credentials. Select the API key using the description.
  • Scenario ID. Paste the test scenario ID you want to use in the build. Copy the ID from the scenario page in LoadView.
  • Error Threshold. Specify an acceptable percentage of sessions with errors that occurred while testing (failed to access the target resource, no keywords/image found, etc.). If the percentage of error sessions is greater than the specified value, the build will be marked as a failure in Jenkins.
  • Average Time. Specify a limit for an average response time measured during test execution. If the limit is reached, the build will be marked as a failure in Jenkins.
  1. Click Save.

Postman Api

View LoadView Test Results

Finally, we have successfully integrated our Postman collection with Jenkins using LoadView as a platform. While our stress test is running, the status is displayed in the Jenkins Console Output in real-time mode.

Monitoring Postman Collection Test

LoadView is one part of the many solutions within the Dotcom-Monitor platform. Dotcom-Monitor also provides easy monitoring tools for our Postman collections. If we have a collection of integration tests used for internal API testing with Postman, and we also want to set up tests to run from outside the local network, we can upload the Postman tests to Dotcom-Monitor. Using the Dotcom-Monitor Postman Collection task we can create automated monitoring tests with alerts on errors. We can specify monitoring locations, a monitoring scheduler, filters, and set up reporting based on monitoring results.

The collection of HTTP requests added will be repeatedly executed with the defined frequency to perform the sequence of calls to the target web API. With that we will have the assertions that were specified for the requests in Postman which will help to verify API responses. If any condition set by assertions is not met the task will be marked as failed.

Load Testing Your API with Postman: Final Thoughts

The development community has widely varying opinions about testing APIs. We have seen how Postman helps us altogether in creating, maintaining, and testing out APIs with such ease. We also looked at a step-by-step guide on how we can simulate concurrent users load testing Postman collection using LoadView. Later we have looked at how we can automate this step using Jenkins integration with LoadView. The tools required to stress out these applications have been simplified lately and it provides immense help testing out complex systems that are dependent on internal and external applications. It helps us to spot the bottlenecks and issues more clearly.

Start load testing your APIs today with LoadView. Sign up for the free trial and receive $20 in load testing credits. Or sign up for one of our private demos with one of our performance engineers. Our engineer will walk you through the full LoadView platform, as well as show you how to integrate LoadView into Postman collections and automating the steps with Jenkins.