API Testing through Postman

Introduction: –

An application programming interface (API) is a computing interface which defines interactions between multiple software intermediaries. It defines the kinds of calls or requests that can be made, how to make them, the data formats that should be used, the conventions to follow, etc.

PostMan: –

Postman is a scalable API testing tool that quickly integrates into CI/CD pipeline. It started in 2012 as a side project by Abhinav Asthana to simplify API workflow in testing and development. API stands for Application Programming Interface which allows software applications to communicate with each other via API calls.

With over 7 million+ users nowadays, Postman has become a tool of choice for the following reasons:

  1. Accessibility – To use Postman, one would just need to log-in to their own accounts making it easy to access files anytime, anywhere as long as a Postman application is installed on the computer.
  2. Use of Collections – Postman lets users create collections for their API calls. Each collection can create subfolders and multiple requests. This helps in organizing your test suites.
  3. Collaboration – Collections and environments can be imported or exported making it easy to share files. A direct link can also be used to share collections.
  4. Creating Environments – Having multiple environments aids in less repetition of tests as one can use the same collection but for a different environment. This is where parameterization will take place which we will discuss in further lessons.
  5. Creation of Tests – Test checkpoints such as verifying for successful HTTP response status can be added to each API calls which help ensure test coverage.
  6. Automation Testing – Through the use of the Collection Runner or Newman, tests can be run in multiple iterations saving time for repetitive tests.
  7. Debugging – Postman console helps to check what data has been retrieved making it easy to debug tests.
  8. Continuous Integration – With its ability to support continuous integration, development practices are maintained.

Using of Postman for API: –

  1. New – This is where you will create a new request, collection or environment.
  2. Import – This is used to import a collection or environment. There are options such as import from file, folder, link or paste raw text.
  3. Runner – Automation tests can be executed through the Collection Runner. This will be discussed further in the next lesson.
  4. Open New – Open a new tab, Postman Window or Runner Window by clicking this button.
  5. My Workspace – You can create a new workspace individually or as a team.
  6. Invite – Collaborate on a workspace by inviting team members.
  7. History – Past requests that you have sent will be displayed in History. This makes it easy to track actions that you have done.
  8. Collections – Organize your test suite by creating collections. Each collection may have subfolders and multiple requests. A request or folder can also be duplicated as well.
  9. Request tab – This displays the title of the request you are working on. By default, “Untitled Request” would be displayed for requests without titles.
  10. HTTP Request – Clicking this would display a dropdown list of different requests such as GET, POST, DELETE, PUT, etc. In testing, the most commonly used requests are GET and POST.
  11. Request URL – Also known as an endpoint, this is where you will identify the link to where the API will communicate with.
  12. Save – If there are changes to a request, clicking save is a must so that new changes will not be lost or overwritten.
  13. Params – This is where you will write parameters needed for a request such as key values.
  14. Authorization – In order to access APIs, proper authorization is needed. It may be in the form of a username and password, bearer token, etc.
  15. Headers – You can set headers such as content type JSON depending on the needs of the organization.
  16. Body – This is where one can customize details in a request commonly used in POST request.
  17. Pre-request Script – These are scripts that will be executed before the request. Usually, pre-request scripts for the setting environment are used to ensure that tests will be run in the correct environment.
  18. Tests – These are scripts executed during the request. It is important to have tests as it sets up checkpoints to verify if response status is ok, retrieved data is as expected and other tests.

Types of Request in Postman: –

Get Request: – Get requests are used to retrieve information from the given URL. There will be no changes done to the endpoint.

Steps to run request

  1. Set your HTTP request to GET.
  2. In the request URL field, input link
  3. Click Send
  4. You will see 200 OK Message
  5. There should be 10 user results in the body which indicates that your test has run successfully.

Post Request: – Post requests are different from Get request as there is data manipulation with the user adding data to the endpoint.

Steps to run request

  1. Set your HTTP request to POST.
  2. Input the same link in request url: https://jsonplaceholder.typicode.com/users
  3. Switch to the Body tab
    1. Select raw option
    1. Choose JSON under text drop down
  4. Enter the payloads
  5. Click Send.
  6. Status: 201 Created should be displayed
  7. Posted data are showing up in the body.

Delete Request: – An HTTP DELETE method is used to delete an existing resource from collection of resources. The DELETE method requests the origin server to delete the resource identified by the Request-URI. On successful deletion of resource, it returns 200 (OK) and 204 (No Content) status code. It may return as 202 (Accepted) status code if request is queued.

Steps to run request: –

  1. Select the “DELETE” in http methods drop down.
  2. Pass the request URI in address bar of Postman.
  3. Add authorization if applicable.
  4. Add headers if applicable.
  5. Click on Send button.
  6. Status code: 200 (OK) and 204 (No Content) will return

Put Request: – An HTTP PUT method is used to primarily update the resource information, but it also can be used to create a new resource (Depends on API development) if requested resource is not available.  If PUT request is made to update resource, it should return 200 (OK) and 204 (No Content) status code

Steps to run request: –

  1. Select the “PUT” in http methods drop down.
  2. Pass the request URI in address bar of Postman.
  3. Pass request body in desired format under Body tab.
  4. Add authorization if applicable.
  5. Add headers if applicable.
  6. Click on Send button.
  7. Status code: 200 (OK) and 204 (No Content) will return

Search the data by Get Request: –

Use Authorization while adding, update and delete the data: –

Preset Header: – helps user very much to avoid re-enter the same data

Links :-

Hope above content would be helpful to you .

Leave a Reply