Postman API Fundamentals Student (part 1)

ariba.dev
7 min readMar 21, 2023

You can think of APIs as being like a waiter at a restaurant, serving as a go-between for the customer and the kitchen.

Relation between client and server help of API

A customer who wants soup doesn’t go into the kitchen to cook. They don’t even have to know how to make soup! They only have to know how to ask the waiter for soup, and expect the waiter will bring back soup.

APIs work the same way, but there are different names for the players involved. Instead of soup, the requester might ask for data or execution of a service.

Different names for the players involved

Types of APIs

Medium

While this article will focus on Web APIs, it is important to know that the term “API” can apply to a broad range of interfaces.

  • Hardware APIs
    Interface for software to talk to hardware.
    Example: How your phone’s camera talks to the operating system.
  • Software Library APIs
    Interface for directly consuming code from another code base.
    Example: Using methods from a library you import into your application.
  • Web APIs
    Interface for communicating across code bases over a network.
    Example: Fetching current stock prices from a finance API over the internet.

Multiple API types may be used to achieve a task. For example, uploading a photo to Instagram makes use of various APIs:

  1. Hardware API for the app to talk to your camera
  2. Software library API for the image to be processed with filters
  3. Web API for sending your image to Instagram’s servers so your friends can like it!

Architectures

There is more than one way to build and consume APIs. Some architecture types you may come across are:

  • REST (Representational State Transfer)
  • GraphQL
  • WebSockets
  • webhooks
  • SOAP (Simple Object Access Protocol)
  • gRPC (Google Remote Procedure Call)
  • MQTT (MQ Telemetry Transport)

😱 Don’t worry about knowing all of these! We will focus on REST APIs in this article since this is the most widely adopted API architecture.

REST APIs
Some traits of REST APIs include not storing session state between requests, the ability to cache, and ability to send and receive various data types. Still confused? Don’t worry, we will learn hands-on very soon in this course!

Accessibility

APIs also vary in the scope of who can access them.

  • Public APIs (aka Open APIs)
    Consumed by anyone who discovers the API
  • Private APIs
    Consumed only within an organization and not made public
  • Partner APIs
    Consumed between one or more organizations that have an established relationship

The API we will use in this course will be a Public, REST, Web API 👀

An API Platform

Postman is an API platform for building and using APIs. Postman simplifies each step of the API lifecycle and streamlines collaboration so you can create better APIs faster, and consume them with ease. That’s why Postman is trusted by over 20 million users worldwide!

Working with APIs then and now: cURL vs Postman

Before Postman, it was common practice to poke at APIs with a command line tool for making HTTP requests called cURL. This tool is still used today, but has its limitations when it comes to collaboration and sharing.

API calls with curl
This is an example of what an API call in the terminal using the curl command looks like. Here we are fetching data about GitHub user postmanlabs

curl https://api.github.com/users/postmanlabs

curl using terminal

It works great, but once you make the call the API response data is lost in the river of the terminal. You also don’t have visibility of the metadata of the response without adding more details to the command.

API calls with Postman
Here is the same call done with Postman. Postman not only shows the response with clean indents and colors, but also allows you to save, organize and share your requests. You can also see all the components of the request and response broken down into tabs, and other helpful details like the response time and status code

How to work with POSTMAN

To get started making requests in Postman, you need to be inside a workspace. Let’s make one!

1. Workspaces dropdown > Create Workspace

2. Name your workspace “Postman API Fundamentals Student Expert” and set the visibility to Public (or Personal if you cannot make a Public workspace on your team). Then click “Create Workspace

3. Success ! Welcome to your empty new workspace.and make collection.

Task: Get books from the Library API

First things first: a librarian must know how to view all the books in the library catalog.

According to the API documentation, you can get all the books in the library by making a request to GET https://library-api.postmanlabs.com/books. Here, GET is the request method and the url is the request URL. We'll cover what that means soon - but first let's get our hands dirty with our first request!

Make your first request

1. Create a new request by either clicking Add a request inside your new Collection, or hovering on your Collection, then clicking the three dots icon and “Add request”

2. Name your request “get books”. Set the request method to GET, and the request URL to GET https://library-api.postmanlabs.com/books. Be sure to hit Save!

3. Send your request by clicking the Send button

View the response

If everything goes well, you will see a response from the server in the lower half of Postman.

It should look something like this: a JSON (JavaScript Object Notation) response body that is an array of book objects. You can scroll down to see more books.

Request methods

When we make an HTTP call to a server, we specify a request method that indicates the type of operation we are about to perform. These are also called HTTP verbs.

Here are some common HTTP request methods that correspond to the CRUD operations mentioned earlier. You can see a list of more methods here.

Request URL

In addition to a request method, a request must include a request URL that indicates where to make the API call. A request URL has three parts: a protocol (such as http:// or https://), host (location of the server), and path (route on the server). In REST APIs, the path often points to a reference entity, like "books".

ProtocolHostPathhttps://library-api.postmanlabs.com/books

Paths and full URLs are also sometimes called API endpoints.

Response status codes

The Postman Library API v2 has sent back a response status code of “200 OK”. Status codes are indicators of whether a request failed or succeeded.

Status codes have conventions. For example, any status code starting with a “2xx” (a “200-level response”) represents a successful call. Get familiar with other status code categories:

status codes

Request-Response pattern

Now you can understand the request response pattern, which represents how computers communicate over a network. An API is the interface that lets us know what kind of response to expect when we make certain calls to a server.

You made an HTTP GET request to https://library-api.postmanlabs.com/books and received a response from the server.

The client is the agent making a request. A client could be a browser or an application you have coded, for example. In our case Postman is the client because that’s how we sent the request.

The request is sent over a network to some server. In our case, we made a request over the public internet to a server located at the address https://library-api.postmanlabs.com.

The server interpreted the request (GET /books) and sent the appropriate response over the network back to the Postman client: a list of books.

That’s it!

Referenced from Postmanlabs

STAY TUNED FOR MORE AMAZING CONTENT

https://twitter.com/ariba_hussain10
https://www.linkedin.com/in/ariba1039/
https://instagram.com/ariba.dev

--

--

ariba.dev

⚡Dart makes my heart Flutter 💙🧑‍💻 • ✨ Software developer🧑‍💻 • Looking for the best remote opportunity in EUROPE