Testing different types of API's in Postman

Different types of Web API’s ?


A Piece of software that makes itself available over the internet is called Web API .Once it is exposed to the network, other software applications can communicate and they can exchange the data.

In Simple , If an API is hosted on the network (WEB).It is called web API.

The most commonly used API on the internet are

  • Simple Object Access Protocol (SOAP)

  • Representational State Transfer (REST)

  • GraphQL

SOAP API:

  • SOAP has been in existence quite long.

  • It’s a protocol with a set of strict rules and standards.

  • Language Independent, it can work on any Internet protocol.

Examples :

  • Transmission Control Protocol(TCP)

  • User Datagram Protocol (UDP)

  • File Transfer Protocol(FTP)

  • Hypertext Transfer Protocol(HTTP)

  • Hypertexts Transfer Protocol Secure(HTTPS)

  • It can only support XML message format only.

  • The way soap works is by sending an envelope. Which consists of all necessary details of SOAP message ,which exchanged between the web service and the client.

Structure of the SOAP Envelope:

Example:


  1. As per the above SOAP message ,The first of the SOAP message is the Envelope element , which is used to indicate the beginning and end of a SOAP message .Which is used to encapsulate the entire SOAP message.

  2. SOAP body Which contains the details of the actual message.

  3. AS per the example the name of the web service is <FullCountryInfo> .

  4. Next comes the Parameters that are accepted by the web service.

Example of SOAP request in POSTMAN :

http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso


Steps :

  1. Open the Postman .

  2. Select the workspace you want to work on.

  3. Create the collection name as CountryInfo.

  4. Add a new request under the CountryInfo collection.




5. Copy the following link in to the "Enter URL" text box.


http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso


6.Select POST method from the drop down.

  • While working with Postman . We have to set the request method to POST because they have to send so much XML data.



7.While working with SOAP we have to send the XML in request body by selecting raw and from the "Text" dropdown we have to select XML. Copy the below XML envelope inside the body.

<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <FullCountryInfo xmlns="http://www.oorsprong.org/websamples.countryinfo"> <sCountryISOCode>String</sCountryISOCode> </FullCountryInfo> </soap:Body> </soap:Envelope>


8. Enter the "CountryISOCode" ,like IN ,US ,CA..etc



9. For this particular API ,We would also need to modify the content-Type header ,by adding new one at the bottom. We have to set the value as application/soap+xml.




10. Now click on send.

11 . We will get the full country Info back.



REST API:

  • REST stands for Representational State Transfer .

  • It is an architectural style. It doesn’t follow any strict rules like SOAP.

  • It mostly works on HTTP/HTTPS protocols.

  • It uses HTTP methods for all CRUD operations.

  1. Create (POST)

  2. Read (GET)

  3. Update (PUT)

  4. Delete (DELETE)

  • It is like a postcard ,which uses less bandwidth as the request doesn’t require SOAP headers for every message.

  • It permits different data formats such as plain text ,HTML ,XML and JSON.

  • To send a request we use resource URI-Endpoint

Example:

Get ListofAll

https://swapi.dev/api/people/

Individual data

https://swapi.dev/api/people/1/


Steps:

  1. Open the Postman.

  2. Create a new request.

  3. Copy the following URL https://swapi.dev/api/people/

  4. Select the GET method from drop down to get the list of people.

  5. Click on send.

  6. we will get the response with list of people .



  • We can authorize to an API by clicking on Authorization tab and selected the "Type" of the auth.

In below example I selected "Basic Auth " and gave Username and Password.




POST : It is used to create a record. We have to send the parameters .

we can send the parameters using query parameters or by body .

In below example I sent using body.




we will see status code as 201 Created in the response header for successful creation of the record .


PUT: We can update the existing record by using PUT method.

Here I am updating the record which I created in the POST.



Delete: Delete is used to delete the existing record .

Note: If record doesn't exists we will get an error message along with error code.



Here I deleted the record by passing the program Id as path parameter to the end point.

We will get the response header as 204 No Content.


GraphQL:

  • GraphQL is a query language and it was designed to deal with some of the situations where REST API’s have shortcomings.

  • When you call a REST API endpoint, it gives us all the information .You must call multiple endpoints to get the required data. This slow down the things in big applications with many users.

  • It was designed by Facebook to deal with these issues.

  • In GraphQL API single endpoint will contain most or all the information needed ,but we have to use queries to filter down the information

  • In GraphQL ,we need to know about the schema or structure of the data.

Ex: https://countries.trevorblades.com/

We use POST request , which will make it easier rather than using GET.


Steps:

1. Open the Postman.

2. Copy the following URL https://countries.trevorblades.com/ in the URL textbox

3. Select the POST method from the dropdown.

4. we should pass the query in the body by checking GraphQL checkbox.


If I want to know the name of the country and language then we have to give following query by passing the parameter as "US" to the code.

{ country(code: "US"){ name languages{ code name } } }

5.Click on send .

6.Got the response with name of the country ,language Name.





Hope this will help you all to get basic knowledge on working with different API’s in POSTMAN.


References: https://www.google.com/books/edition/API_Testing_and_Development_with_Postman/93QqEAAAQBAJ?hl=en&gbpv=1&pg=PR1&printsec=frontcover

https://reqres.in/



27 views0 comments

Recent Posts

See All

Headless Browser in Python

What is a headless browser? A headless browser can access any website but unlike normal browsers (which you currently use) nothing will appear on the screen. Everything is done on the backend side inv