0% found this document useful (0 votes)
4 views16 pages

Postman API Course

The document outlines the Postman API Fundamentals Student Expert Program, detailing the concepts of APIs, their types, and the use of Postman for making API requests. It includes practical tasks for creating workspaces, collections, and making GET and POST requests, as well as using variables and scripting within Postman. The content emphasizes the importance of APIs in modern software development and provides a structured approach to learning API interactions using Postman.

Uploaded by

thrisharajesh856
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views16 pages

Postman API Course

The document outlines the Postman API Fundamentals Student Expert Program, detailing the concepts of APIs, their types, and the use of Postman for making API requests. It includes practical tasks for creating workspaces, collections, and making GET and POST requests, as well as using variables and scripting within Postman. The content emphasizes the importance of APIs in modern software development and provides a structured approach to learning API interactions using Postman.

Uploaded by

thrisharajesh856
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Key Learnings

Postman API Fundamentals Student Expert Program

Thrisha Rajesh
1BG23CS170
February 21 2025
Contents
What are APIs? ............................................................................................................................... 1
Application Programming Interfaces (APIs)............................................................................... 1
Types of APIs........................................................................................................................... 2
Introducing Postman ................................................................................................................... 2
API Request................................................................................................................................. 4
Task 1: Creating a Workspace ................................................................................................. 4
Task 2: Creating a Collection .................................................................................................. 4
Request methods ...................................................................................................................... 5
Response status codes .............................................................................................................. 5
Task 3: Making a request ......................................................................................................... 6
Request Parameters ..................................................................................................................... 7
Postman Variables .................................................................................................................... 7
Query Parameters .................................................................................................................... 7
Task 4: Applying query parameters ......................................................................................... 8
Path Variables .......................................................................................................................... 8
Path vs. query parameters ........................................................................................................ 9
Task 5: Applying path parameter ............................................................................................. 9
Sending data using POST.......................................................................................................... 10
Task 6: Make a POST request ............................................................................................... 10
Task 7: Add an authorization header ......................................................................................11
Task 8: Use Postman Auth ......................................................................................................11
Introducing to Postman variables and scripting .........................................................................11
Variables .................................................................................................................................11
Scripting................................................................................................................................. 12
Task 9: Add a script to a request ............................................................................................ 12
Task 10: Get a book id using scripting .................................................................................. 13
Task 11: Make a request to update......................................................................................... 14
Task 12: Make a request to delete ......................................................................................... 14
Codegen feature ..................................................................................................................... 14
Postman API Fundamentals

What are APIs?


Application Programming Interfaces (APIs)
• APIs - Building blocks of modern software - allow for sharing of resources and services
across applications, organizations, and devices.
• It’s a contract that allows code to talk to other code.
• Importance of APIs:
- It helps developers integrate exciting features and build automation without
reinventing the wheel
e.g. Using a Weather API instead of launching your weather balloons
- Allow enterprises to open up their product for faster innovation
e.g. Apps that interact with Twitter or Meta APIs by posting on your behalf or reading
tweets
- They can be products themselves
e.g. Software as a Service (SaaS) products like Stripe's payment APIs or Twilio's text
messaging and email APIs
• APIs are not just for developers (tech and IT industries) as it is identified that most of the
non-developer roles (management, solutions architects, business and data analysts,
educators and researchers) make use of APIs.

• APIs – A Digital Restaurant:


- Client: The requester e.g. browser, web app, mobile app. → Customer
- API – Simplifies interface for interacting with the backend → Waiter
- Server – The backend where the processing happens → Kitchen

Figure 1.1: Networking Team and their Restaurant Analogy

Thrisha Rajesh 1|Page


Postman API Fundamentals

Types of APIs:
- Based on broad range of interfaces to which APIs can be applied:
1. Hardware APIs: Interface for software to talk to hardware.
e.g. Phone’s camera that to talks to OS.
2. Software Library APIs: Interface for directly consuming code from another
code.
e.g. Methods from a library which we import into our application.
3. Web APIs: Interface for communicating across code bases over a network.
e.g. Fetching current stock prices from a finance API over the internet.
- Based on the architecture:
1. REST (Representational State Transfter)
2. GraphQL
3. WebSockets
4. Webhooks
5. SOAP (Simple Object Access Protocol)
6. gRPC (Google Remote Procedure Call)
7. MQTT (MQ Telemetry Transport)
- Based on the access:
1. Public APIs (a.k.a Open APIs): Consumed by anyone who discovers the API.
2. Private APIs: Consumed within an organization and not made public.
3. Partner APIs: Consumed between one or more organizations that have an
established relationship.
- API used in this course: Public, REST, Web API

Introducing Postman
• Postman: An API platform for building and using APIs.

Figure 2.1: Postman API Platform

Thrisha Rajesh 2|Page


Postman API Fundamentals

• Working with APIs:


1. API calls with cURL (Client URL): Command line tool for making HTTP requests.
2. API calls with Postman: One can send a request to an endpoint, retrieve data from a
data source, or test an API’s functionality.
No need to enter commands in a terminal.

Figure 2.2: Postman API call overview

• Postman’s vision for an API – First World consists of:


- APIs are considered a #1 priority.
- APIs are easily consumable.
- APIs are easily discoverable.

Figure 2.3: Postman’s “API – First World” – A graphic novel

Thrisha Rajesh 3|Page


Postman API Fundamentals

- Access link for the fictional story: [Link] (Explores a future


where software development prioritizes APIs as the primary building block).

API Request
Task 1: Creating a Workspace – let’s become a digital librarian:
- CRUD (Create, Read, Update, Delete) – operations performed using a REST API.
- The steps involved are as follows:
1. Navigate to [Link]
2. Select Blank Workspace as Template and name it as "Postman API
Fundamentals Student Expert".

Figure 3.1: Creating a Workspace

Task 2: Creating a Collection – Postman Library API v2 – to organize all our API requests
- Select a blank collection and name it as “Postman Library API v2”.

Figure 3.2: Creating a Collection

Thrisha Rajesh 4|Page


Postman API Fundamentals

Request methods – HTTP verbs:


- While making an HTTP call, the request methods have to be specified which indicates
the type of operation being performed

Figure 3,3: Request methods used in Postman

• Request URL:
- It indicates where to make an API call.
- It has 3 parts:
1. Protocol: such as http:// or https://
2. Host: Location of the server.
3. Path: Route on the server.
- E.g.: [Link]
Response status codes:
- They are the indicators of whether a request failed or succeeded.

Figure 3.4: Response tatus code categories

Thrisha Rajesh 5|Page


Postman API Fundamentals

Task 3: Making a request


- The steps involved are as follows:
1. Adding a new request inside the collection created in the previous section and
name it as “get books” – to get (view) all the books in the library.
2. Set the request method as GET and the request URL as [Link]
[Link]/books
• Viewing the response
- The response body is in JSON (JavaScript Object Notation) – an array of book
objects.

Figure 3.5: GET request method to get (read) all the books in the library

• Request – Response pattern:


- Client:
An agent making a request.
e.g.: Browser, Application
Here it’s the Postman
- Network:
Request is sent over a network to some server.
Here it’s the request made over the public internet to a server located at the address
[Link]
- Server:
Interprets the request and send an appropriate response over the network back.
Here the request GET /books is provided with the response - a list of books.

Thrisha Rajesh 6|Page


Postman API Fundamentals

Figure 3.6: Request – Response pattern

Request Parameters
Postman Variables:
- Values can be saved as variables to reuse them and easily sensitive information like
API keys.
- Once variable is defined, it’s values is accessed using {{variableName}}.
- Steps involved in setting the “baseUrl” variable:
1. Select the entire base URL [Link] and set it as a
new variable – baseUrl
2. Set the scope at the collection level.
3. {{baseUrl}} now means the entire base URL.
- Variable with two values:
1. Initial values: Value initially when a collection is forked (copied) or imported.
2. Current value: Variable value resolved by the Postman.
It’s local to our Postman account and not public.
It’s better practice to keep here ONLY the API keys.

Query Parameters
- Key – value pairs added to the path end which refine our request.
- Syntax:
1. Single query parameter: ?<key>=<value>
e.g.: GET [Link]
2. Multiple query parameters: ?<key1>=<value1>&<key2>=<value2>
e.g.: GET [Link]
- Allow us to add filters or extra data to our responses.

Thrisha Rajesh 7|Page


Postman API Fundamentals

Task 4: Applying query parameters


API allow us to add query parameters to GET /books request
• Single query parameter – Get all fiction books
- Steps followed are:
1. Duplicate the “get books” request and rename it as “get fiction books”.
2. Using Params tab, add a query parameter with key – genre and value – fiction.
3. The request URL now looks like: {{baseUrl}}/books?genre=fiction
• Multiple query parameters – Get all the available fiction books
- Steps followed are:
1. In the same request, add another query parameter with key – checkedOut and
value – false.
2. The request URL now looks like:
{{baseUrl}}/books?genre=fiction&checkedOut=false

Figure 4.1: Setting up query parameters in a request

Path Variables
- Another way of passing request data to an API – Path variables / Path parameters.
- Syntax: {username}
- Single path parameter:
e.g.: GET [Link]
- Multiple path parameters:
e.g.: GET [Link]

Thrisha Rajesh 8|Page


Postman API Fundamentals

Path vs. query parameters:

Figure 4.2: Difference between path and query parameters

- /users/:username and /users/{username} both are acceptable.


Task 5: Applying path parameter
• Get a book by id:
- Add a request and name it as “get book by id”.
- The request URL: {{baseUrl}}/books/:id
- In the Params tab, add the id (path variable) value.

Figure 4.3: Setting up path variable/parameter

• Debugging requests in the console:


- All requests we make and their responses are logged in the Postman Console.
- The path variable :id in the request URL gets replaced by its specific value that we’ve
set up in the Params tab.

Thrisha Rajesh 9|Page


Postman API Fundamentals

Sending data using POST


- A JSON body data has to be submitted to add or update structured data.
- Body tab enables us to specify that data we need to send with a request.

Task 6: Make a POST request


• Add a new book:
- Steps followed are:
1. Add a new request and name it as “add book”.
2. Request method set as POST and the request URL: {{baseUrl}}/books.
3. Body tab chosen with the raw data – JSON format.
4. Book details (Title, Author, Genre, Published_year) entered as the body data.
5. Results in 401 Unauthorized error so let’s authorize the request by adding api-key
to its header.

Figure 5.1: JSON body format with POST

• Authorization (a.k.a Auth)


- To avoid unauthorized people accessing the data.
- Methods for authorizing a request:
1. Basic Auth: Username and Password.
2. OAuth: Delegated authorization.
3. API Keys: Secret strings registered to a developer from an API portal.
• Getting an API key:
- In Postman Library API v2 ,
Header name: api-key
Header value: postmanrulz
- Headers – Specify the type of data we wish to have in our response.

Thrisha Rajesh 10 | P a g e
Postman API Fundamentals

Task 7: Add an authorization header


• Adding api-key to the request header:
- Under “add a book” request, Headers helper table is updated with the key – api-key
and value – postmanrulz.
Task 8: Use Postman Auth
Postman has an Auth helper that makes authorizing requests easier.
Adding api-key to our entire collection so that all requests will send the key.
• Delete api-key header under a request and add Auth at the collection level:
- Authorization tab at the collection level is selected with the API Key and it’s type as
auth.
- Respective key – api-key and value – postmanrulz is entered.

Figure 5.2: Authorization made with the Auth helper

Introducing to Postman variables and scripting


Variables
• Advantages of saving values as variables:
1. Reuse values to keep our work DRY (Don’t Repeat Yourself).
2. Hide sensitive values like API keys from being shared publicly.

Thrisha Rajesh 11 | P a g e
Postman API Fundamentals

• Variable scopes:
- From broadest to narrowest, these scopes are global, collection, environment, data,
and local.

Figure 6.1: Postman variable scopes

- If a variable with the same name is declared in two different scopes, the value stored
in the variable with narrowest scope will be used.
Scripting
Postman allows us to add automation and dynamic behaviours to our collections with scripting.
• Scripts automatically executed by Postman during two events:
1. Pre-request script: Immediately before a request is sent
2. Post-response script: Immediately after a response comes back
• pm object:
- pm: Helper object in Postman that gives us access to data about our Postman
environment, requests, responses, variables and testing utilities.
E.g:
- [Link]() → JSON response body from an API is accessed.
- [Link](“baseUrl”) → To get collection variables.
- [Link](“variableName”, ”variableValue”) → To set collection
variables.
Task 9: Add a script to a request
Scripting is done using JavaScript.
- Under “add a book” request, add the JavaScript code -
[Link]([Link]())
- This scripting logs the JSON response from the API into the console.

Thrisha Rajesh 12 | P a g e
Postman API Fundamentals

Figure 6.2: Scripting in Postman – logs the JSON response into the console

• Defining local variables in JavaScript:


- const - variables that won't change value.
- let - allows us to reassign the value later.
Task 10: Get a book id using scripting
• Setting of collection variables: [Link]("variableName", value)
• Getting collection variables: [Link]("variableName")
• Scripting done in post-response tab explained as:
- Save the “id” value from the response to a variable named “id”.
- Save the id as a collection variable named “id”.
• The “id” variable has been automatically assigned the “id” of our new book as its current
value.

Figure 6.3: Scripting in Postman – set “id” as a collection


variable

Thrisha Rajesh 13 | P a g e
Postman API Fundamentals

Task 11: Make a request to update


Update a book by id by making a request (authorized with the API key) using PATCH
• CheckOut a book:
- Add a new request and name it as “checkout a book” and set its method as PATCH.
- Request URL set to {{baseUrl}}/books/:id
- Path variable id set to {{id}}
- Raw JSON body with checkedOut set as true.

Figure 6.4: PATCH request method to update a book id

Task 12: Make a request to delete


- Add a new request and name it as “delete a book”.
- Set the request method as DELETE.
- Request URL set to: {{baseUrl}}/books/:id
- Path variable id of a book to be deleted is set to {{id}} in Params tab
- Verification: Try it again – it should result in 404 Not Found error (So, the book with
the specified id has been deleted).

Codegen feature
- API requests can be generated using common coding languages like Python,
JavaScript, C, NodeJS and more.

Thrisha Rajesh 14 | P a g e

You might also like