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
You are on page 1/ 52
{{Intro.to.
APIs} Bit Project x Postman Presents
} Reimagining the Classroom Leveraging technology to rethink the way we teach
bitproject.org/join/student Presenters
Kevin Vuong Jefferson Chhen Michelle Hu
Developer Relations Developer Developer {{Intro to APIs}} ❏ What are APIs? ❏ Using Postman to Test Endpoints ❏ Creating Postman Collections ❏ BitBloxs ❏ Collection Runners Before we get started:
Download Postman!
getpostman.com/downloads Make a Postman Account! What is an API? APIs allow programs to interact with each other without exposing source code Why are APIs Useful?
Faster Development You don’t need to build everything from scratch.
Makes development easier and faster!
Why are APIs Useful?
Easy Data Access
Data APIs make authenticated access to all kinds of data easy! What is a RESTful API? RESTful APIs allow programs to communicate with each other using HTTP (Hypertext Transfer Protocol) Requests
HTTP
Webpage Server HTTP Methods GET: retrieves data
POST: assigns a value to an empty object
PUT: re-assign/ change a value
DELETE: gets rid of an existing value
Endpoints Status Code
❏ Endpoint is the receiving
end of all your API requests.
❏ It takes a request + data
and returns a response.
❏ Endpoints will always return
a status code API Testing Game bitbloxs.herokuapp.com Objective ● Fill adjacent squares with your team’s color using API ● Try to get the biggest blob, the most amount of connected squares with your team’s color ● Notice, some commands can’t do certain actions. Rules ● Four colors for four teams: orange, yellow, blue and green ● Get the most connected squares for your color ● Volunteers will each lead a team - split into groups ● ~5-10 minutes, final result only decided when time is up What is cURL? cURL is a command-line tool for getting or sending data including files using URL syntax. Open your Terminal/Command Prompt GET Requests We use a GET request when we want to query a collection of data or a specific piece of data
GET requests return a data object
(usually in JSON) and a 200 status code
curl --location --request GET
"https://bitbloxs.herokuapp.com/boxes?api_key=thisistheapikey" POST Requests POST requests are used to send data to the server. It creates a new object.
❏ You are “posting” data to the API
❏ POST requests generally don’t return data, just a 200 status code
curl --location --request POST
"https://bitbloxs.herokuapp.com/change/23/yellow?api_key=thisistheapikey" PUT Requests A PUT request is used to change existing data
In contrast to POST, which creates
new data
curl --location --request PUT
"https://bitbloxs.herokuapp.com/change/23/blue?api_key =thisistheapikey" DELETE Requests A DELETE method is used to delete existing data Explained
curl --location --request DELETE
"https://bitbloxs.herokuapp.com/delete/23?api_key=thisisth eapikey" What is Postman? Postman is a collaboration platform for API development.
Makes testing APIs super simple!
Postman Features
Easy Testing Postman allows easy API testing with a click of a button.
No need to use curl command!
Postman Features
Collections Postman also allows you to organize a set of API requests.
This makes it quick and easy access to
see/edit/delete a request. Creating a New Collection Create a Collection
We are going to create a request to get a single box’s color
Postman Features
Environments Environments allow easy switching between, development and production servers. Environments let you customize requests using variables so you can easily switch between different setups without changing your requests. Creating an Environment
Click the gear icon. Then, click ADD
Postman Features
Credentials Variables in a Postman collection can be used in the entire collection - allows you to encapsulate sensitive data Create Variables for your Credentials
https://bitbloxs.herokuapp.com/ Create Variables for your Credentials
An API Key is required to access an API. Our API’s key is
thisistheapikey Open Collection
Make sure that you click the menu icon on the
bottom left to open the menu! Creating a GET Request Use Authentication Creating the route
input the following link:
{{url}}boxes/22 Postman Features
Documentation Postman also auto generates beautiful documentation.
This makes it quick and easy for
developers to understand all of the features of an API. Let’s Explore
In the collection click the “Get all boxes” request.
Click the send button and see what happens! Experiment with Postman POST in Postman Double click the Change color request in the collection.
Your Postman client
should look like this POST in Postman On the link, replace <string:color> to either blue, orange, green, or yellow.
Your link should look
something like this. POST in Postman On the link, replace <int:box_id> with a number from 1 to 400.
Your link should look
something like this.
After this step, click the
Send button! Psst Repeat for Put/Delete Requests how to win BitBloxs.herokuapp.com
May the best
team win! Postman Features
Collection Runner Collections are groups of requests that can be run together as a series of requests, against a corresponding environment.
Click the Runner Button
Postman Features
Collection Runner Configure the POST route to look something like this.
Replace {{box_id}} with the
number and add the color you want. How we use Postman ❏ Simulating backend service for Frontend Developers ❏ Testing endpoints without using curl Apply here!