Get To Know About Postman Tool
Blog

Get To Know About Postman Tool

Postman is a great tool for prototyping APIs, and it also has some powerful testing features. So, here I share how to integrate Postman's tests into your build automation to make it elite. I've used Postman in one of my projects as a way to interact with APIs which is also explained here. As a tool to setup complex HTTP requests, this is  much convenient than request specs, Cucumber, or hand-rolling them in even your favorite HTTP library.

A Little About Postman
Postman is a Google Chrome app for interacting with HTTP APIs. It presents you with a friendly GUI for constructing requests and reading responses. The people behind Postman also offer an add-on package called Jetpacks, which includes some automation tools and, most crucially, a Javascript testing library. This post will walk you through an example that uses those testing features. While they won't replace your focused unit tests, they do breathe new life into testing features from outside your applications. This makes it extremely valuable for functional testers or for developers who love to test outside-in.

HTTP VERBS generally used in POSTMAN
GET : Read a specific resource (by an identifier) or a collection of resources.
HEAD : Works same as GET, just returns the header.
PUT : Update a specific resource (by an identifier) or a collection of resources. Can also be used to create a specific resource if the resource identifier is known before-hand.
DELETE : Remove/delete a specific resource by an identifier.
POST : Create a new resource. Also a catch-all verb for operations that don't fit into the other categories.

HTTP Response Codes for Status
Using top 10 HTTP status codes

200 – ok – general success
201 – created – New resource has been created
204 – no content – Success and response body empty. The resource was successfully deleted.
304 – Not Modified – The client can use cached data
400 – Bad Request – The request was invalid or cannot be served. The exact error explained in error payload.
401 – Unauthorized – The request requires an user authentication
403 – Forbidden – The server understood the request, but is refusing it or the access is not allowed.
404 – Not found – There is no resource behind the URI
405 - Method not allowed
422 - Unprocessable Entity
500 – Internal Server Error

You have to get the POSTMAN from https://www.getpostman.com/ and download the google chrome POSTMAN extension and signup for free to create an account. After creating the account when you log in to the POSTMAN tool, you have to have the URI to test ,whether the URI gives the correct response or not ,after verifying the results and codes.

Steps for doing  the API Testing using POSTMAN.

Step 1: Open POSTMAN tool and log in with your credentials.
Step 2: Get the Request URL(Uniform Resource Locator) of the API.
Step 3: Paste that URL into the URL space given in the POSTMAN.
Step 4: Select the Method which you want to perform,For example GET,PUT,POST,DELETE.
(Note: The endpoint of the URL would be different for different Methods).

Step 5: Put the Headers with Key and Value field.
Step 6: Put the body part and select raw option ,incase you are using any POST/DELETE Method.
Step 7: Recheck the given URL and click on send button and observe the response in JSON format.

*Let us take a scenario of creating a new profile in a XYZ website and after creating that new profile we will try to retrieve its data from the DB using POSTMAN Tool.
 

Pre requisites:
1. First, user has to logout from the XYZ website,and we need to have a resource endpoint to which we are posting the new profile.

2. We would also need the body part of the profile what we are posting.

3. After successfully creating the new profile we have to make the Request URL from the response, to fetch that newly created profile.

Step 1: Get the request URL and paste in the URL space provided in POSTMAN.
ec2-54-238-127-209.ap-northeast-1.compute.amazonaws.com/v1/profiles

Step 2: Select the POST Method.

Step 3: Put the headers and body part and select the raw option of input type for Body part.
Headers:

Content-Type  : application/json

Authorization : Bearer 60557ad5f4ddd047c846928642b7aab1b94f3681

X-CSRF-Token : eMb4uODH3rNwb6r-SUt6rb9mPWtu69kdoAjcbIGgOMQ

Body Part:

{"name": "ABCD",

"account" :

{ "is_new": 1, "email": "abcd@gmail.com",

 "password": "password" }

}

 


Step 4: Click on the Send button and observe results.

Response would come in JSON Format:

Status code: 201 Created

{  "id": "438b5097-57c9-411f-9e4f-abd04192b2d1", "href": "ec2-54-238-127-209.ap-northeast-1.compute.amazonaws.com/v1/profiles/438b5097-57c9-411f-9e4f-abd04192b2d1",

  "type": "profile",

  "account": {

"href":"http://ec2-54-238-127-209.ap-northeast-1.compute.amazonaws.com/v1/profiles/438b5097-57c9-411f-9e4f-abd04192b2d1/account",

 "data": { "id": "d76c0eda-2525-43d0-b9bf-69fe84860cfc",

"name": "1qw111ww2.singh",

"email": "1qw111ww2.singh@david.com",

 "created_time": "1463050948",

 "last_login_time": "1463050948",

 "status": "1",

 "email_verification_status": "0",

"phone": "",

"phone_verification_status": "0",

"href":"http://ec2-54-238-127-209.ap-northeast-1.compute.amazonaws.com/v1/accounts/d76c0eda-2525-43d0-b9bf-69fe84860cfc",

"type": "account",

"profile":{"href":"http://ec2-54-238-127-209.ap-northeast-1.compute.amazonaws.com/v1/accounts/d76c0eda-2525-43d0-b9bf-69fe84860cfc/profile",

"data": [

{

"id": "438b5097-57c9-411f-9e4f-abd04192b2d1",

"href":"http://ec2-54-238-127-209.ap-northeast-1.compute.amazonaws.com/v1/profiles/438b5097-57c9-411f-9e4f-abd04192b2d1",

"type": "profile"

}

 ]

},

"session_id": "cXH295AMUKo5nx40aNhIwtNmo3c9x8WQrLu9uCMSBQ8",

"session_name": "SESS15dfa26f31ea72e21097a903a2b1b263",

"token": "dTbg9wLVhpqT2ShezRq7orHl5zTJxEwbPlflsxIJinY"

}}}</pre>

 

Screen shot of the Response:

Postman Screenshot

Now We have successfully created a new profile.Let us now retrieve the profile data that we just have created,from the DB through below request URL.

Request URL:
ec2-54-238-127-209.ap-northeast-1.compute.amazonaws.com/v1/profiles/438b5097-57c9-411f-9e4f-abd04192b2d1

Response:  200 Success

{

 "id": "438b5097-57c9-411f-9e4f-abd04192b2d1",

"name": "A2?!@B=22A",

 "cover_picture": {

"thumbnail":"http://ec2-54-238-127-209.ap-northeast-1.compute.amazonaws.com/sites/default/files/styles/thumbnail/public?itok=zcW4M1JC",

"medium":"http://ec2-54-238-127-209.ap-northeast-1.compute.amazonaws.com/sites/default/files/styles/medium/public?itok=2poEpR1K", "large":"http://ec2-54-238-127-209.ap-northeast-1.compute.amazonaws.com/sites/default/files/styles/large/public?itok=OcLV1fUn"

 },

"about": null,

"short_bio": null,

"gender": "",

"display_picture": {

"thumbnail":"http://ec2-54-238-127-209.ap-northeast-1.compute.amazonaws.com/sites/default/files/styles/thumbnail/public?itok=zcW4M1JC",

"medium":"http://ec2-54-238-127-209.ap-northeast-1.compute.amazonaws.com/sites/default/files/styles/medium/public?itok=2poEpR1K",

"large":"http://ec2-54-238-127-209.ap-northeast-1.compute.amazonaws.com/sites/default/files/styles/large/public?itok=OcLV1fUn" },

"created_time": "1463050948",

"updated_time": "1463050948",

"status": "0",

"href":"http://ec2-54-238-127-209.ap-northeast-1.compute.amazonaws.com/v1/profiles/438b5097-57c9-411f-9e4f-abd04192b2d1",

"type": "profile",

"location": {},

"connection_request_count": "0",

"events": {

"href":"http://ec2-54-238-127-209.ap-northeast-1.compute.amazonaws.com/v1/profiles/438b5097-57c9-411f-9e4f-abd04192b2d1/events",

"data": []

},

"account": {

"href":"http://ec2-54-238-127-209.ap-northeast-1.compute.amazonaws.com/v1/profiles/438b5097-57c9-411f-9e4f-abd04192b2d1/account",

"data": [{"id": "d76c0eda-2525-43d0-b9bf-69fe84860cfc",

"href":"http://ec2-54-238-127-209.ap-northeast-1.compute.amazonaws.com/v1/accounts/d76c0eda-2525-43d0-b9bf-69fe84860cfc",

"type": "account"

}]},

"works": {“href":"http://ec2-54-238-127-209.ap-northeast-1.compute.amazonaws.com/v1/profiles/438b5097-57c9-411f-9e4f-abd04192b2d1/works",

"data": []

},  "current_campus": {

"href":”http://ec2-54-238-127-209.ap-northeast-1.compute.amazonaws.com/v1/profiles/438b5097-57c9-411f-9e4f-abd04192b2d1/current_campus",

"data": []},

"Educations":

{"href":"http://ec2-54-238-127-209.ap-northeast-1.compute.amazonaws.com/v1/profiles/438b5097-57c9-411f-9e4f-abd04192b2d1/educations",

"data": []

},

"reading_list": {

    "href": "http://ec2-54-238-127-209.ap-northeast-1.compute.amazonaws.com/v1/profiles/438b5097-57c9-411f-9e4f-abd04192b2d1/reading_list",

    "data": []

  },

  "skills": {

    "href": "http://ec2-54-238-127-209.ap-northeast-1.compute.amazonaws.com/v1/profiles/438b5097-57c9-411f-9e4f-abd04192b2d1/skills",

    "data": []

},

"connections": {"href":"http://ec2-54-238-127-209.ap-northeast-1.compute.amazonaws.com/v1/profiles/438b5097-57c9-411f-9e4f-abd04192b2d1/connections",

"data": []

},

"connections_mutual": {“href":"http://ec2-54-238-127-209.ap-northeast-1.compute.amazonaws.com/v1/profiles/438b5097-57c9-411f-9e4f-abd04192b2d1/connections_mutual",

"data": []

},"followers": {"href":"http://ec2-54-238-127-209.ap-northeast-1.compute.amazonaws.com/v1/profiles/438b5097-57c9-411f-9e4f-abd04192b2d1/followers",

"data": []

},"profiles_following": {"href":"http://ec2-54-238-127-209.ap-northeast-1.compute.amazonaws.com/v1/profiles/438b5097-57c9-411f-9e4f-abd04192b2d1/profiles_following",

"data": []},

"topics_subscribed": {"href":"http://ec2-54-238-127-209.ap-northeast-1.compute.amazonaws.com/v1/profiles/438b5097-57c9-411f-9e4f-abd04192b2d1/topics_subscribed",

"data": [

{

"rel_created_time": "1463050948",

"id": "74501461-5f98-407a-b7c0-90846058accb",

"href":"http://ec2-54-238-127-209.ap-northeast-1.compute.amazonaws.com/v1/topics/74501461-5f98-407a-b7c0-90846058accb",

"type": "topic"}]},

"stories": {

"href":"http://ec2-54-238-127-209.ap-northeast-1.compute.amazonaws.com/v1/profiles/438b5097-57c9-411f-9e4f-abd04192b2d1/stories",

"data": []

},"calendar":{

“href":"http://ec2-54-238-127-209.ap-northeast-1.compute.amazonaws.com/v1/profiles/438b5097-57c9-411f-9e4f-abd04192b2d1/calendar",

”data": []}}

 

Image of newly created profile retrieval.

Postman Screenshot

Download the Drupal Guide
Enter your email address to receive the guide.
get in touch