POSTMAN AND SPRING BOOT

This article will give you insights on the Postman tool and how to perform GET, POST, PUT and DELETE operations.

What is Postman?

It is a tool which comes handy while testing the API functionalities. We can test an API by proving the rest mapping path and get a response.

POSTMAN UI:

Lets look at the points one by one.

source code

This specifies how the API is mapped. i.e Is it GET mapping or Post mapping or Put Mapping or Delete.There are multiple Method requests as shown in the image but 4 of them are most commonly used i.e

  1. GET
  2. POST
  3. PUT
  4. DELETE

From here we can call our API. We need to give the mapping here.

eg: in the above case the url is:

localhost:8080/postman/getUsers

here,

localhost: hostname

8080: port

postman/getuser : Request mapping

i) Params : This is used when we need to give the parameters to the API, eg: key- value.

ii) Authorization: used for proper authentication to access API.

iii) Headers : used to set headers passed to the API.

iv) Body : used while passing the request body to the API. There are multiple formats in which we can send the request body, eg: raw, binary etc.

Note

If raw is selected, there are some formats given to send the request body i.e javascript, json, plain text etc as shown in the image below.

v) Pre-request Script: Script that needs to be executed before the request is made

vi) Tests: Tests scripts executed while the request is made.

We can pass the request body or headers in this area.

To Understand the working of each request, i recommend to go through the source code.

Get mapping is done when we want to get the data from the API by passing the url and headers if required.

Eg: The following request will get me all the users and their related information.Screenshot from 2021–03–23 20–19–49

Post Mapping is done when we want to insert an object. In this case I am passing the object values in the form of json.

This is basically used when we need to update an object. We can pass parameters such as user id.

It is basically used when we want to delete a particular user.