DEV Community

Cover image for APIs 101 with POSTMAN: A Beginners Guide (2022)
 Dev Kumar Gupta
Dev Kumar Gupta

Posted on

APIs 101 with POSTMAN: A Beginners Guide (2022)

Postman has become a popular tool for developers for Creating, Testing and Managing APIs. But what are APIs in the first place and why are they used?
👉Let’s find out what is an API, what is it used for, what is Postman and it's role as an API management tool.

So, the Agenda of the Blog is:

  1. Introduction to APIs and Postman
  2. Requests and Responses
  3. Hands on detailed lab session
  4. Follow-up Opportunities and Learning Resources

API stands for Application Programming Interface
To explain what an API is, we take a simple example...

APIs: A Digital Restaurant
Suppose you, the customer, visit your favourite restaurant and request for a bowl of ice-cream for which the waiter acts as a mode of communication between you and the chef. The function of the waiter is to communicate to you whether there is a stock of ice-cream or not, if there is, he will bring it for you.

APIs: A Digital Restaurant

Similarly, the role of an API is to act as the middleman for the communicator between softwares. [ Remember, don’t call the waiter at your favourite restaurant an API, he probably won’t understand 🙂 ]

The above depiction shows us how in the Software Development World, the client (the person requiring the data), sends a request which is taken by the API to the Server (where the data is stored) and the action is performed accordingly.

Why do we use APIs and not directly access the data from the servers??

What is an API

APIs make the task of developers easier by removing the need to create every service from scratch.


You must have used the Instagram app.
Let me demonstrate how the APIs help us with an example of it's simple implementation on Instagram.

APIs through Instagram

Step 1: You select a photograph from your gallery to upload (API required to fetch that photograph)
Step 2: You modify the photograph by applying filters (API to modify this photograph)
Step 3: You finally publish this photograph (API sends this photograph to the server to store it)
Step 4: Instagram displays the photograph to you and your followers (API fetched the photograph from the server)

So, you see that the process which happens within seconds on our devices, runs a lot of API calls in the background, but thanks to the developers of Instagram, you do not experience the lag in service.

Let us now understand the role of Postman.

WHAT IS POSTMAN?

Postman is a collaborative API development platform that makes it easy for us to create, test and monitor APIs. It's environment makes it a popular Industry standard equipment for companies like PayPal, Uber, Atlassian etc.

What is Postman

In earlier days, the complex structure of the command line interface, while implementing API requests, made it difficult to read and manage the code. So, to solve this problem, Postman was created which had a minimalistic UI (User Interface) helping developers manage APIs.

Now, let’s dive into the "Technical Part" about APIs… don’t stop, I assure you it’s very simple 😎

The interaction with the API starts with making a REQUEST, which carries the following parameters …

  1. Method (GET, POST, PUT etc.)
  2. Address/Endpoint (URL – Uniform Resource Locator)
  3. Path

1. Requests – Methods and Endpoints:
The Method parameter specifies which type of action will be performed in our API call, some main actions are -
GET – for retrieving information
POST – for sending information
PUT/PATCH – for updating information
DELETE – for deleting the information

Request Methods and Endpoints

2. Address/Endpoint (Parts of a URL):
The Protocol is the scheme of the request, here it is an HTTPS request.

The Host is the address of the server, the place where the code lives which you need to connect to.

3. The Path is the destination where the request can be heard or executed.

The Body is that part of the API which contains the data that we want send or receive.


Request Body:

Requests Body

The data payload (which is the data sent by the client to your API), is optional but often supplied with the POST and PUT requests.
The Data can be sent in various formats; Text, HTML, XML etc. but the most used format is JSON or JavaScript Object Notation.


A feel of the Postman platform:

Postman Platform:

We enter the public workspace on the platform which is made to be visible to everyone and to learn how to interact with APIs.

Now, we should not tamper with the original code unless we are absolutely sure about what we are doing. So, to avoid problems in the public workspace, we fork a copy of the public workspace into our personal workspace (which only we have access to). This function is similar to forking a git repository from Github.

My Workspace

Forked public workspace is now in “My workspace”.

Now, to understand what we are about to do, we read the Documentation.

Documentation

To perform our very first action, we accessed the Get Data file and we sent a valid API call to google.com and received a status 200 OK.
Status 200 OK – means that the request was correct and the desired response has been sent to the client.

Status 200 OK

Now, whenever we google something, we can see this on the URL bar:

Google Search

This q symbolizes Query, the term which we are looking for (here q=Postman). Basically, it tells the search engine what we are looking for.

On Postman, we can set the query parameter in a similar way.


Retrieving Data using API call:
We then navigate to the Book API and used the GET method to call the Base URL set to a path - /book which retrieved random books from the database and displayed it in JSON format.

GET Method

To get a particular book, we set the path parameter, id, to different values.

Adding Data using API call:
We then added a request to add data to the server by using the POST method. But first read the documentation to get a idea on what code to add in the JSON.

POST Method

Whenever we want to add some information, we enclose it within the Body of the request and select type as JSON.

Every book should have a unique id. Hence, we take an arbitrary value of id and send in the API call. Upon successful adding of the data, we get a 201 Created which is for a new resource being created.

201 Created

To verify if your data was sent correctly, we go to the Get data tab and enter the id we sent for the post request.

Checking GET Method

If we get back the same data we added in the POST method, then our implementation was correctly executed.

Modifying Data using API call:
To Modify the data, we use the PUT method and we add this request in a new tab.
We input the JSON text from the documentation in the similar way to POST method.

204 No Content

We get a 204 No Content because it is a confirmation that the data was added correctly, but there is nothing to return here.
We can again verify the information by requesting a GET data method.

Deleting Data using API call:
To delete a particular book, we add a new request with the DELETE method.
We specify the path (/book) and an id to delete the book at that id.
On running the command, we get an output “Book with id ___ is deleted.”

DELETE Method

On checking in Get Data, we get a message saying “Book not found” because it has been deleted successfully.

We also had this UI which made it simple to understand the various changes to the data by presenting it visually.

UI for checking API Implementation


Wrapping Up: 🌠
We learnt about APIs and it’s uses, why is Postman used and how to implement basic API calls using Postman 🤩

Way forward: 📈
We can continue Learning APIs as a Student Expert and get certified 🎓

Get Certified by Postman


Credits

This Blog is my complete breakdown of the Session - APIs 101 with Postman by Satabrata Paul @SatabrataYo (Postman Student Expert and Core Member GDSC HITK) which was conducted on 5th March, 2022.

You can find the complete YouTube tutorial here

👉 You can follow me on Twitter @Dev_ikr

Thanks for sticking around till the end 😃

  • #PostmanStudent #PostmanAPI

Top comments (0)