Manual API Testing using Postman
Reliable API calls are critical to any decoupled application. Whether it an easy configuration change to an entity or updating the Drupal core, both of them can alter the API response and cause application-breaking changes on the front-end. An API test suite can be careful for these API breaking changes by running a slew of tests against your endpoint. And once you got to create an API test suite, Postman delivers.
Why Postman tool?
Postman may be a simple GUI for sending HTTP requests and viewing responses. It is built upon an in depth set of power tools, which are incredibly easy to use. Postman helps you perform a spread of functions starting from selenium online training
- organizing requests into collection and folders,
- sharing common values across requests with environment variables,
- scripting tests with the built-in node.js based runtime,
- and at last, automating it all using Postman’s very own CLI — Newman.
- Install native Postman Application
- Postman for Mac/Windows/Linux:
- Go to https://www.getpostman.com/apps and download the application based on the OS you are using and follow the steps prompted to successfully install the Postman application.
After you have installed Postman successfully, your postman window should look like:
- If you have accomplished this step, you are all set to take the next flight.
- Making the first http request in Postman:
- Since we have installed the Postman app successfully, it is now time to start testing the API with Postman by making first ever HTTP request to server.
What is HTTP?
- The Hypertext Transfer Protocol (HTTP) is designed to enable communications between clients and servers. HTTP works as a request-response protocol between a client and server. A web browser could also be the client, and an application on a computer that hosts an internet site could also be the server.
- Example: A client (browser) submits an HTTP request to the server; then the server returns a response to the client. The response contains status information about the request and should also contain the requested content.
- Most common http methods:
- GET : The GET method is employed to retrieve information from the given server employing a given URI. Requests using GET should only retrieve data and will haven't any other effect on the info.
- POST : A POST request is employed to send data to the server, for instance , customer information, file upload, etc. using HTML forms.
- PUT : PUT is employed to send data to a server to create/update a resource. Replaces all the present representations of the target resource with the uploaded content.
- PATCH : PATCH is employed to update partial resources. For instance, once you only got to update one field of the resource, PUTting an entire resource representation could be cumbersome and utilizes more bandwidth.
- HEAD : HEAD is nearly just like GET, but without the response body. HEAD transfers the status line and therefore the header section only.
- 6. DELETE : The DELETE method deletes the required resource.
- 7. OPTIONS : the choices method describes the communication options for the target resource.
Testing GET Requests
Let’s now jump directly to test those API’s. Suppose we've an API which fetches the user information of a specific application. To test this we'll need to use GET request. The GET request is explained below:
For sample requests, visit https://reqres.in/
- For making the first HTTP request(GET):
- Make a collection in Postman — To make a collection in Postman, click on New->Collection->CollectionDemo(Any Collection Name you wish)->Create
- Make a Request — To make a request, click on New->Request->GetUser(Any request name you wish)->Select the Collection you wish to save request in(Present in bottom of dialog box)->Save to Collection Demo
- By now, we have created our first request, now we need to pass different parameters in the request to get the expected response.
- In the “Enter Request URL” text box type : https://reqres.in/api/users?page=1
- Click on “Send” Button
- You should be able to see the below response in the Body section:
- you ought to be delighted you've got successfully tested your first API request.
Testing POST Requests
Now, suppose we'd like to make a user into a application meaning we are sending data or feeding data to an application. For these sort of requests we use POST request. In POST request we send data/parameter within the body of the request, and in response thereto , Selenium API returns some data to us which validates the user has been created. The response can either be a hit message or the id of the new user created and time when the user was created.
- For making the first HTTP request(POST):
POST Request — to form a POST request, click on New->Request->CreateUser(Any request name you would like )->Select the gathering you wish to save lots of request in(Present in bottom of dialog box)->Save to Collection Demo
- From the Dropdown select POST
- In the “Enter Request URL” text box, type : https://reqres.in/api/users
- Click on Body Tab and select “Raw” radio button
- In the text box, paste :
- Click on Send button
- User should see the below response:
- Also, check for correct status code, in this case you should get : ‘Status:201 Created’
You have successfully tested your POST request too, similarly you'll try your hands with PUT, PATCH, DELETE etc.
- Check for expected response.
- Check for correct status code.
- Check for Time (Response Time), it should be acceptable as per business more info at selenium online training Hyderabad.
- Always perform negative tests to verify that the API doesn’t respond if data is tampered.
That’s all for this blog. Happy Testing!!
Read my next blog on “Automation of REST Apis with Postman”