March 24, 2020 How to Use Postman to Test APIsAPI TestingBy Jacob SharirThis blog will give a step-by-step guide on how to use Postman to test your APIs in order to simplify the API testing process. APIs make it possible for any two separate applications to transfer and share data between them. They also make it easier for an application's users to execute actions without having to use the application’s GUI. From the developers' POV, it's an easy way to execute certain functionalities of their app and test it as well.Using APIs on a daily basis might become cumbersome, as one might have dozens or even hundreds of APIs that he or she needs to use or test. That makes it difficult to keep up with their exact request’s address(es), header(s), authorization credential(s) etc. And it makes it harder to test the API for functionality, security, and exception handling.Table of Contents:What is Postman?How to Use Postman to Test APIs How Postman Helps Share BlazeMeter’s APIRunning a Postman CollectionUsing APIs Within Your Own App or Script With PostmanWhat is Postman?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. In case you don’t have Postman installed, you’ll need to download it and install it.Get the latest best practices for API testing & monitoring.GET MY GUIDEHow to Use Postman to Test APIs Postman is very convenient when it comes to executing APIs. Once you’ve entered and saved them, you can simply use them over and over again, without having to remember the exact endpoint, headers, API keys, etc.Here is a detailed example explaining how to enter a new API request using CA BlazeMeter’s ‘test create’ API, but you can do this for the product you are developing:Launch Postman by clicking on the logo. After it completely loads the main screen follow this steps to create your collection of requests:On the “collections” tab click on the “+” button to create a new collection. A new collection will appear and you will be able to edit its name, description, and many other settings.Then right click on that new collection and select “add request” to create your first request.Select the recently created request and enter the API endpoint where it says ‘Enter request URL’ and select the method (the action type) on the left of that field. The default method is GET but we will use POST in the example below.4. Add authorization tokens/credentials according to the server side requirements. The different methods/protocols Postman supports are: No Authentication, Basic Authentication (provide username and password only), Digest Authentication, OAuth 1.0, OAuth 2.0, Hawk Authentication, AWS Signature and NTLM Authentication [Beta]. 5. Enter headers in case they are required. Enter a POST body in case it is required. In this example, we are creating a BlazeMeter test that requires a JSON payload with relevant details.If you wish to execute this API now, hit the ‘Send’ button, which is located to the right of the API request field. You can also click on the ‘Save’ button beside it to save that API request to your library.That’s it! Now you know how to enter your API request to Postman and save it to your library.How Postman Helps Share BlazeMeter’s APIOne of Postman’s fantastic features is ‘Collections’. ‘Collections’ allow you to group together several APIs that might be related, or perhaps should be executed in a certain sequence.For example, in the previous screenshot, you can see a collection that includes 4 APIs that are all required to create and run a BlazeMeter test. The first two APIs create the test object - the first of the two applies the necessary configuration, and the following API uploads the script file needed to run it. The last two APIs start and stop the test we created previously. Obviously, they should be executed in that sequence, hence the collection will be sorted accordingly.Running a Postman CollectionIn order to run a Postman Collection, you will need to use a feature called ‘Collection Runner’ following this steps: In the Postman GUI, in the bottom right corner of the screen, click the ‘Runner’ button. 2. Drag and drop the desired collection or folder to the runner window. In our case, it will be the collection called ‘BlazeMeter API’.There are additional configuration parameters that you may define. However, this is not mandatory. For example, you can specify the number of iterations you wish to run the collection for, as well as add delays between each API request. There is also an option to choose your ‘Environment’. Environments allow you to customize requests using variables that might include environment specific values. This is extremely helpful when you are testing against several environments, like the development environment, the production environment, etc. To set up a new environment, click on the eye icon on the top right side of the Postman GUI and select ‘add’. You will be able to add a new one as well as its respective variables.Using APIs Within Your Own App or Script With PostmanPostman also has a feature called ‘Snippets’. You can use it to generate code snippets in a variety of languages and frameworks, such as Java, Python, C, cURL and many others.This is a huge time saver. A developer can easily integrate APIs with his or her own code without too much hassle. To use it, click on the code tab on the right side of the screen of Postman’s GUI.You can now run API testing through BlazeMeter! START TESTING NOW Related ResourcesOpenAPI vs. Swagger: 5 Reasons You Should Use BothWriting Python API Tests with Apiritif
Jacob Sharir Domain Expert Jacob Sharir is a BlazeMeter domain expert, with more than 7 years of experience in performance testing, test automation, and respective open-source frameworks. While leading a global team of technical experts, Jacob is proficient in the fields of Continuous and Performance testing. He is focused on assisting the Product team with exploring creative solutions, and increasing products’ value, quality and stability while helping customers improve their testing efficiency.