DEV Community

Cover image for POSTMAN & API 101
Nishant Wanjari
Nishant Wanjari

Posted on • Updated on

POSTMAN & API 101

Greetings everyone,

I attended an amazing workshop “API’S 101 WITH POSTMAN” hosted by Postman Student Experts, Mufeeda Patel and Zaid Khan, organized by RAIT-ACM Student Chapter, R.A.I.T DYPU, Navi Mumbai in collaboration with Postman.
In this blog I have written about my key takeaways from the workshop!

The topics covered in the session by POSTMAN STUDENT EXPERT were –

  1. What is API?
  2. How Do API Work?
  3. Why API?
  4. Request And Response In-Depth.
  5. Role Of API In Tech-Companies.
  6. What Is Postman?
  7. Hands-on Practice On Postman.

Session's Major Takeaways

01. What Is An API? ?

API - Application Programming Interface.

API is an interface that allows communication between computers or computer programs.

Image 02

02. How Do API Works?
API architecture is usually explained in terms of client and server. The application sending the request is called the client, and the application sending the response is called the server.

Non-Technical Approach

Example 01 - Restaurant Analogy

The best API analogy is from a restaurant.

When you go to a restaurant, the menu of the place is the front-end.
But all the real work - cooking of the food - happens in the kitchen that you may not see. Hence, the kitchen is the back-end.
At a restaurant, you yourself don't go to the kitchen and bring your order back from the chefs, right? That's what waiters are for! And that's exactly what APIs do too!

Waiters take your order details (REQUEST) and relay it to the kitchen so the chefs can cook it up. And when they're done, waiters bring back the delicious cooked food (RESPONSE) back to your table as requested by you.

Image 01

In essence,

  1. Website/ Server/ Backend - Kitchen.
  2. API Customer/ User/ Client - You.
  3. Document/ Frontend - Menu.
  4. API - The Waiter.

APIs collect your inputs from the front-end via a request and relay it to the back-end where the inputs get processed and certain output is returned back to you as a response!

Example 02 - Switch Board.
Think API as a switch board on the wall of your home. You can plug chargers for your phones, laptops, desktops and can run different devices. Here the switch board acts as an API which hides the electrical wiring. As a user, you can simply get your work done.

03. Why API?
A big advantage of using them is that you don't necessarily need to know the back-end logic yourself. As long as you know what data to input (REQUEST) and what to expect in the output (RESPONSE), you can totally use an API to do all the processing for you.

Technical Approach Towards API
These requests and responses usually take place over HTTP in a real-world application. The front-end makes an HTTP request with the inputs in its request body at a certain API endpoint and is returned an output in a form of an HTTP response with a certain response body.

04. Request And Response In-Depth
Let's understand about the REQUEST and RESPONSE in-depth.
REQUEST - When you search for something in google you are actually making a request to the Google server passing a query.
RESPONSE - It is the output presented after the process.

Non-technical Example - RESPONSE And REQUEST

Suppose the professor asked Class Representative (CR) to bring him a book from the library.
Here,

  • Asking is the request protocol.
  • Class Representative is address of the server.
  • Library is the endpoint.
  • Book is the query.

*Technical Example - RESPONSE And REQUEST *
See the image below, you can see the URL is -
3
https://www.google.com/search?q=hello

Here,

  • https:// is request protocol.
  • www.google.com is the address of the server.
  • /search is the endpoint.
  • ?q=hello is query.

05. Role Of API In Tech-Companies
Major tech companies create their own API for developers.

  • PayPal
  • Twitter
  • Google
  • Amazon

API's Role In PayPal -
The "Pay with PayPal" function is built with APIs to ensure that the end application can only do what it needs to, without being exposed to sensitive data or gaining access to unintended permissions.

When the USER clicks the "Pay with PayPal" button, the application sends an ORDER request to the PayPal API, specifying the amount.
Then, a pop-up authenticates the user and confirms their purchase. Finally, if everything goes to to plan, the API sends confirmation of payment back to the application.

API's Role In Twitter -
TWITTER
To know more about Twitter's API -
https://developer.twitter.com/en/docs/twitter-api

API's Role In Google -
Image desc87
To learn more about Google's API -
https://cloud.google.com/api-gateway/docs/architecture-overview

API's Role In Amazon -
AMAZONTo learn more about Amazon's API -
https://docs.aws.amazon.com/apigateway/latest/developerguide/welcome.html

05. What Is POSTMAN?

Postman is a collaborative API development platform that makes it easier for developer to create, test and monitor APIs with a UI.

One of the most famous API testing platform used 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 MINIMILIASTIC UI (User Interface) helping developers manage APIs.

Key Features Of Postman -

  • Easy to setup.
  • Minimal API knowledge.
  • Collaborative.
  • User-friendly interface for interacting with an API.
  • Allows both manual and automated QA Engineers to create and maintain an API testing framework.
  • Great tool to assist in both manual and automated API testing.

Prerequisites -

  • Workspaces - Workspace allows us to organize your API folders and requests.
  • Requests/Responses - A request is a combination of the URL, HTTP headers, Body or Payload whereas response is output.
  • Collections - Collections are a group of saved requests.
  • Environment - It allow us to run the Requests and Collections against different data sets.

HTTP Requests

HTTP - Hypertext Transfer Protocol
There are different kinds of HTTP requests that mean different things:

  1. GET - Request to retrieve the information.
  2. POST - Request to add your own information.
  3. PUT - Request to update your information.
  4. PATCH - Request to 'modify' an existing resource.
  5. DELETE - Request to delete the data you added. This kind of API architecture is commonly called as REST API and the API is said to be RESTful.

Image des544545cription

Basic Info for request-response codes:

Different Status code family -
200 family : Code is used successfully
400 family : There is some problem from the user side.
500 family : There is some problem from the server side.

06. Hands-on Practice Of API Using POSTMAN
LET'S GET STARTED -

  1. Create an account on POSTMAN.
  2. Use the link given below, it will lead to Basics of API tab - https://www.postman.com/postman/workspace/postman-student-api-101-workshop/collection/13935790-3246e804-99c9-444e-8248-59da3f9f6122?action=share&creator=23583603
  3. Fork the link provided in your own workspace.
  4. On left hand side you will get Endpoint URL and some instructions.
  5. {base_url}: http://postman-student.herokuapp.com/

Making Requests for Joke API with the /joke path

01. GET

  1. Copy the Endpoint URL.
  2. Paste it in the GET Joke request.
  3. Click Send button.
  4. Response is received as "Hello World" with status code 200 OK. It indicates success. HELLO WORLD

Note - By default, we have 4 jokes with id [1-4]
To get a random joke: {base_url}/joke
To get a specific joke: {base_url}/joke/{id of joke}

02. POST

  • Request to add your own information.
  • To send a new joke: {base_url}/joke
  • Change GET method into POST by clicking on dropdown.
  • Add the body to your request in the body tab.
  • Select JSON from the dropdown.
  • Paste the information.
  • Add joke with a Unique Id.
  • Status code - 201 Created.

03. PUT

  • Request to updates the entire object on the server.
  • To update an existing joke: {base_url}/joke
  • Add a new request with the method PUT.
  • Name request as Update Joke.
  • Put the entire object that you're trying to update in the body of your request.
  • Leave the ID as it is, but make the changes in your joke.
  • We get response as _ No Content_ which basically indicates that our response has been updated.
  • Go back to GET request to check if the joke has been updated or not.

Note - Make sure you change the id to the id you used earlier in the POST request and make the changes you want in the body before hitting send.

04. DELETE

  • It is used to delete information.
  • To delete a joke: {base_url}/joke/{id of joke}
  • Specify the joke id which we want to delete.
  • Click send.
  • The request was successful.

So, that was all about API’s and POSTMAN.

FINAL THOUGHTS
Learning new stuff is always fun and more importantly implementing them there on. The workshop was a great learning experience and made me familiar with how I can use Postman seamlessly to test the APIs I create.

Thank You for your time.

Nishant Wanjari
Student | B.Tech - IT |

Hashtags -

PostmanAPI #API101 #PostmanStudent #raitacm #Postman #postmanapi #postman

Imagription

Top comments (0)