Postman Basics and Special Features

Keploy API Fellowship: Session 5

·

4 min read

What is Postman?

Postman is a tool that allows us to build and easily work with APIs. Postman is used to build HTTP requests that we send to the server running the API.

Getting started with Postman

In order to know what kind of methods an API offers, we need to refer to the API documentation. We're using Simple Books API whose documentation is linked here.

HTTP/HTTPS

HTTP stands for Hypertext Transfer Protocol. It allows for the communication between different systems. It's most commonly used to transfer data from a web server to a browser in order to allow users to view web pages.

HTTPS stands for Hypertext Transfer Protocol Secure. HTTPS protocols are more secure since they use an SSL (secure sockets layer) certificate, which helps create a secure encrypted connection between the server and the browser. All APIs should use HTTPS.

The HTTP request message will contain: URL (address), Request method (GET, POST, PUT, …), Headers (User-Agent: Postman), Body … try to recall from the previous sessions what all of these terms mean. The HTTP response message will contain: Status code (200, 404, 500, …), Headers, Body … again try to recall from the previous sessions what all of these terms mean.

GET request

The GET method is one of the most commonly used methods of HTTP. It is usually implemented to request a particular resource data from the Web server by specifying the parameters as a query string (name and value pairs) in the URL part of the request.

Postman collections and variables

Variables enable you to store and reuse values in Postman. By storing a value as a variable, you can reference it throughout your collections, environments, requests, and test scripts.

Postman Collections are a group of saved requests. Every request you send in Postman appears under the History tab of the sidebar. On a small scale, reusing requests through the history section is convenient. But on a larger scale, storing requests together is more convenient. You can save requests so that you can re-use them later on. All requests need to be added to a Postman collection. Typically you will have a Postman collection for each API.

We are storing the base address of the API in a collection variable called baseUrl. Our saved baseUrl will be displayed as {{baseUrl}} in the address bar. Variables allow us to avoid repeating the same information. Variables allow us to easily make changes.

Query parameters

JSON is the most popular format that APIs use to send data. Query parameters start after the ? in the URL. Example : {{baseUrl}}/books?type=fiction …. The format is key=value. Muliple query parameters are delimited in the URL with an &. Example: foo=1&bar=2

Depending on the API, some query parameters can be optional or mandatory. A response status 400 indicates an issue with the request data. You can enable and disable parameters by clicking the checkbox associated with each key-value pair.

Path variables

:bookId is a path variable in the URL… This endpoint allows us to specify a value that changes all the time, depending on the book. ":bookId" is just a placeholder and does not get sent. You can use path variables in combination with query parameters (if the API accepts this).

POST request / API Authentication

A POST request allows you to send data in the request body. The endpoint for submitting orders requires authentication. Some APIs/endpoints are public and require no authentication. Other APIs/endpoints are private and require authentication. An access token is temporary password generated by the API. To send JSON, select the POST request method and from the Body select Raw and from the list JSON.

JSON format

JSON - short for JavaScript Object Notation - is a popular format for storing and exchanging data. You need to specify valid JSON, otherwise the server won't understand your request. Use double-quotes "" for strings, separate key-value pairs with a comma sign. Numbers and booleans don't need to be between quotes. Postman indicates when your JSON is invalid.

Random test data

You can use a special type of Postman variable to generate random data. Example: {{$randomFullName}}

PATCH request

A PATCH request is typically used for updating existing data. A PATCH usually does a partial update, by changing only some of the properties.

DELETE request

A DELETE request is used for deleting data. If you try to get the same data with a GET request, you will get a 404 Not Found status code.

To understand more in depth features about Postman, please refer to this FreeCodeCamp link. In case you wish to join Keploy API Fellowship, here is the link.