SlideShare a Scribd company logo
1 of 73
Understanding
APIs
How APIs and
RESTful APIs work
behind the scenes
What is an API?
1
Application
Programming
Interface
But not a “visual” interface like what we
see in this presentation
1
It’s how one computer
can talk to another
computer.
It doesn’t matter what programming
language you’re using. JavaScript,
Python, PHP, Java, C and every other
modern language supports RESTful APIs.
More on this in a bit...
There are many types
of APIs.
But RESTful APIs are most
commonly talked about these days.
RESTful APIs are
what we’re talking
about today, too.
Think of an
API as a
waiter as a
restaurant.
Art by iconicbestiary at https://www.freepik.com/iconicbestiary
Art by iconicbestiary at https://www.freepik.com/iconicbestiary
What can I get
for you?
Art by iconicbestiary at https://www.freepik.com/iconicbestiary
Your finest
pizza!
The waiter
relays the
message to
the kitchen.
Art by iconicbestiary at https://www.freepik.com/iconicbestiary
Where the
chef makes
the food.
Art by freepik at https://www.freepik.com/freepik
Then the
waiter
brings your
food to you.
Art by iconicbestiary at https://www.freepik.com/iconicbestiary
It’s that simple!
Just always keep this metaphor in mind.
Remember the restaurant.
RESTful APIs are meant
to be simple.
Let’s look at a real life
example with actual
computers.
This is a site that uses an
API to collect flight prices
from other websites.
These are
airline
services.
They hold
all the
data.
Skyscanner
will ask
each one
for flight
data.
Now you
can see all
the flight
prices from
other
websites
Computers use APIs to
talk to each other over
the internet.
What programming
languages can we
use?
Art by artmonkey at https://www.freepik.com/artmonkey
What programming
languages can we
use?
Art by artmonkey at https://www.freepik.com/artmonkey
We can use any
modern language
that you’d use for a
website.
● Python
● JavaScript
● PHP
● Java
● C
● Ruby
● Etc
What are
RESTful APIs?
REST is a type of API
Art by freepik at https://www.freepik.com/freepik
REpresentational
State
Transfer
Simply put:
● Client computer asks another
computer for data, or to take an
action
SWAPI
The Star Wars API
https://swapi.co/
JavaScript Demo
fetch('https://swapi.co/api/people/')
.then(res => res.json())
.then(response => console.log(response))
Hello, JSON
Hello, JSON
JavaScript Object Notation
Most languages have a data structure
that looks like a JavaScript Object.
One day, someone decided it should
be a standard.
Then it became the standard.
Request Methods:
● HTTP GET
● HTTP POST
● HTTP PUT
● HTTP DELETE
● HTTP PATCH
The first method:
● HTTP GET
● HTTP POST
● HTTP PUT
● HTTP DELETE
● HTTP PATCH
GET
Requests
How do the work?
GET Requests
● When you load a website.
That’s a GET request
● It’s a request to get data from
another computer
● You’re simply asking for data
and you’re not asking to
perform a task
● You’re not creating, updating or
deleting data
● Most common request type
HTTP Methods for RESTful Requests
HTTP
Method
CRUD Operation Example URL(s)
GET Read
HTTP GET http://website.com/api/users/
HTTP GET http://website.com/api/users/1/
POST
Requests
How do the work?
POST Requests
● Do not go through the standard
URL, but use a URL as the
endpoint
● Ask another computer to create
a new resource
● Returns data about the newly
created resource
HTTP Methods for RESTful Requests
HTTP
Method
CRUD Operation Example URL(s)
GET Read
HTTP GET http://website.com/api/users/
HTTP GET http://website.com/api/users/1/
POST Create HTTP POST http://website.com/api/users/
DELETE
Requests
How do the work?
DELETE Requests
● Do not go through the standard
URL, but use a URL as the
endpoint
● Ask another computer to delete
a single resource or a list of
resources
● Use with caution
HTTP Methods for RESTful Requests
HTTP
Method
CRUD Operation Example URL(s)
GET Read
HTTP GET http://website.com/api/users/
HTTP GET http://website.com/api/users/1/
POST Create HTTP POST http://website.com/api/users/
DELETE Delete HTTP DELETE http://website.com/api/user/1/
PUT/PATCH
Requests
How do the work?
PATCH Requests
● Do not go through the standard
URL, but use a URL as the
endpoint
● Ask another computer to
update a piece of a resource
● Are not fully supported by all
browsers or frameworks, so we
typically fall back on PUT
requests
● Example: Updating a users first
name
PUT Requests
● Do not go through the standard
URL, but use a URL as the
endpoint
● Ask another computer to
update an entire resource
● If the resource doesn’t exist,
the API might decide to
CREATE (CRUD) the resource
HTTP Methods for RESTful Requests
HTTP
Method
CRUD Operation Example URL(s)
GET Read
HTTP GET http://website.com/api/users/
HTTP GET http://website.com/api/users/1/
POST Create HTTP POST http://website.com/api/users/
DELETE Delete HTTP DELETE http://website.com/api/user/1/
PUT Update/Replace HTTP PUT http://website.com/api/user/1/
PATCH Partial Update/Modify HTTP PATCH http://website.com/api/user/1/
More details at https://restfulapi.net/http-methods/
Consuming
APIs
Art by iconicbestiary at https://www.freepik.com/iconicbestiary
APIs can be written in almost
any server-side language.
Art by starline at https://www.freepik.com/starline
APIs will generally return
one of two types data
structures:
JSON or XML
Art by starline at https://www.freepik.com/starline
JSON Example
{
"key_val_example": "value",
"array_example": [
'array item 1',
'array item 2',
],
"object_example": {
"key1": "value1",
"key2": "value2"
}
}
Art by starline at https://www.freepik.com/starline
XML Example
<example>
<field>
Value
</field>
<secondField>
Value
</secondField>
<nestedExample>
<nestedField>
Value
</nestedField>
<nestedSecondField>
Value
</nestedSecondField>
</nestedExample>
</example>
APIs can be consumed in
almost any language.
Art by starline at https://www.freepik.com/starline
Browsers use JavaScript for
their API requests.
Servers use any language that
runs on that computer.
Art by starline at https://www.freepik.com/starline
Common API
Responses
What are they?
Requests and
Responses
When you request data from a
server using GET, POST, PUT,
PATCH or DELETE… that’s a
request.
When the server returns your
data… that’s a response
Requests and
Responses
Responses will always come
with an HTTP Status Code.
And these “status codes” tell you
what’s wrong (or right) without
needing to give you text back to
read.
Common HTTP
Status Codes
Healthy Responses (2--)
● 200 — OK.
Request accepted.
● 201 — Created.
POST requests often return 201s when a resource is created.
● 202 — Accepted.
When a request is accepted but its not done processing.
Maybe the task goes into a queue.
Common HTTP
Status Codes
Redirect Responses (3--)
● 301 — Moved Permanently.
When the endpoint has permanently changed. Update your
endpoint.
● 302 — Found.
The endpoint you’re accessing is temporarily moved to
somewhere else.
Common HTTP
Status Codes
Client Responses (4--)
● 400 — Bad Request.
Server cannot or will not process your request. Often this is
due to malformed API keys or an invalid payload.
● 401 — Unauthorized.
You’re not allowed here. Usually this is because you’re
missing authentication credentials (API keys)
● 403 — Forbidden.
The servers understands your request but won’t execute it.
Your API keys might not have the right permissions or your
trying to use an endpoint that you don’t have access to.
● 404 — Not Found.
There’s nothing here. Move along, move along.
● 405 — Method Not Allowed.
You’re using the wrong HTTP Method. The endpoint might
only accept GET requests and you might be POSTing to it,
for example.
Common HTTP
Status Codes Server Responses (5--)
● 500 — Internal Server Error.
The server had a problem and couldn’t process the request.
This is the only time you are out of control.
Just For Fun Find out
what a 418
response is
API Security
Art by freepik at https://www.freepik.com/freepik
API Keys
● API keys are “passwords” to
access an API. These are your
authentication credentials.
● Almost every website requires
API keys to perform some action.
● Facebook's Graph API is a good
example
graph.facebook.com/codingforeverybody
Access token
required.
Access tokens are
usually generated
with an API key.
Matching 400 status
code.
“Bad Request”.
Something is missing.
Access token
required.
Access tokens are
usually generated
with an API key.
Other services might
throw you a 403 or
405 status.
Art by Sapann Design at https://www.freepik.com/sapann-design
Summary
Think of an
API as a
waiter as a
restaurant.
Art by iconicbestiary at https://www.freepik.com/iconicbestiary
HTTP Methods for RESTful Requests
HTTP
Method
CRUD Operation Example URL(s)
GET Read
HTTP GET http://website.com/api/users/
HTTP GET http://website.com/api/users/1/
POST Create HTTP POST http://website.com/api/users/
DELETE Delete HTTP DELETE http://website.com/api/user/1/
PUT Update/Replace HTTP PUT http://website.com/api/user/1/
PATCH Partial Update/Modify HTTP PATCH http://website.com/api/user/1/
Most APIs are secured with API keys
Art by freepik at https://www.freepik.com/freepik
Free Resources
● https://restfulapi.net/http-methods/
● https://httpstatuses.com/
● https://swapi.co/
Art by rawpixel.com at https://www.freepik.com/rawpixel-com
Questions?

More Related Content

Similar to Understanding APIs.pptx

Nom Nom: Consuming REST APIs
Nom Nom: Consuming REST APIsNom Nom: Consuming REST APIs
Nom Nom: Consuming REST APIsTessa Mero
 
Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...
Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...
Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...Nguyen Duc Phu
 
REST API Quizes TestWarez 2019
REST API Quizes TestWarez 2019REST API Quizes TestWarez 2019
REST API Quizes TestWarez 2019Aleksander Zaleski
 
Web Services and Android - OSSPAC 2009
Web Services and Android - OSSPAC 2009Web Services and Android - OSSPAC 2009
Web Services and Android - OSSPAC 2009sullis
 
Do not automate GUI testing
Do not automate GUI testingDo not automate GUI testing
Do not automate GUI testingAtila Inovecký
 
Scraping the web with Laravel, Dusk, Docker, and PHP
Scraping the web with Laravel, Dusk, Docker, and PHPScraping the web with Laravel, Dusk, Docker, and PHP
Scraping the web with Laravel, Dusk, Docker, and PHPPaul Redmond
 
Intro to-php-19 jun10
Intro to-php-19 jun10Intro to-php-19 jun10
Intro to-php-19 jun10Kathy Reid
 
HTTP - The Protocol of Our Lives
HTTP - The Protocol of Our LivesHTTP - The Protocol of Our Lives
HTTP - The Protocol of Our LivesBrent Shaffer
 
Webservices: The RESTful Approach
Webservices: The RESTful ApproachWebservices: The RESTful Approach
Webservices: The RESTful ApproachMushfekur Rahman
 
RefCard RESTful API Design
RefCard RESTful API DesignRefCard RESTful API Design
RefCard RESTful API DesignOCTO Technology
 
Developing Brilliant and Powerful APIs in Ruby & Python
Developing Brilliant and Powerful APIs in Ruby & PythonDeveloping Brilliant and Powerful APIs in Ruby & Python
Developing Brilliant and Powerful APIs in Ruby & PythonSmartBear
 
The Power of Open Data
The Power of Open DataThe Power of Open Data
The Power of Open DataPhil Windley
 
api_slides.pptx
api_slides.pptxapi_slides.pptx
api_slides.pptxadewad
 
Getting Started with Public APIs
Getting Started with Public APIsGetting Started with Public APIs
Getting Started with Public APIsEryn O'Neil
 
Advanced Web Development in PHP - Understanding REST API
Advanced Web Development in PHP - Understanding REST APIAdvanced Web Development in PHP - Understanding REST API
Advanced Web Development in PHP - Understanding REST APIRasan Samarasinghe
 
MuleSoft Surat Virtual Meetup#21 - MuleSoft API and RAML Design Best Practice...
MuleSoft Surat Virtual Meetup#21 - MuleSoft API and RAML Design Best Practice...MuleSoft Surat Virtual Meetup#21 - MuleSoft API and RAML Design Best Practice...
MuleSoft Surat Virtual Meetup#21 - MuleSoft API and RAML Design Best Practice...Jitendra Bafna
 

Similar to Understanding APIs.pptx (20)

Nom Nom: Consuming REST APIs
Nom Nom: Consuming REST APIsNom Nom: Consuming REST APIs
Nom Nom: Consuming REST APIs
 
Cqrs api
Cqrs apiCqrs api
Cqrs api
 
Are you ready to adopt GraphQL?
Are you ready to adopt GraphQL?Are you ready to adopt GraphQL?
Are you ready to adopt GraphQL?
 
Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...
Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...
Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...
 
REST API Quizes TestWarez 2019
REST API Quizes TestWarez 2019REST API Quizes TestWarez 2019
REST API Quizes TestWarez 2019
 
Web Services and Android - OSSPAC 2009
Web Services and Android - OSSPAC 2009Web Services and Android - OSSPAC 2009
Web Services and Android - OSSPAC 2009
 
Do not automate GUI testing
Do not automate GUI testingDo not automate GUI testing
Do not automate GUI testing
 
Scraping the web with Laravel, Dusk, Docker, and PHP
Scraping the web with Laravel, Dusk, Docker, and PHPScraping the web with Laravel, Dusk, Docker, and PHP
Scraping the web with Laravel, Dusk, Docker, and PHP
 
Intro to-php-19 jun10
Intro to-php-19 jun10Intro to-php-19 jun10
Intro to-php-19 jun10
 
HTTP - The Protocol of Our Lives
HTTP - The Protocol of Our LivesHTTP - The Protocol of Our Lives
HTTP - The Protocol of Our Lives
 
Webservices: The RESTful Approach
Webservices: The RESTful ApproachWebservices: The RESTful Approach
Webservices: The RESTful Approach
 
RefCard RESTful API Design
RefCard RESTful API DesignRefCard RESTful API Design
RefCard RESTful API Design
 
Developing Brilliant and Powerful APIs in Ruby & Python
Developing Brilliant and Powerful APIs in Ruby & PythonDeveloping Brilliant and Powerful APIs in Ruby & Python
Developing Brilliant and Powerful APIs in Ruby & Python
 
Cqrs api v2
Cqrs api v2Cqrs api v2
Cqrs api v2
 
Api testing
Api testingApi testing
Api testing
 
The Power of Open Data
The Power of Open DataThe Power of Open Data
The Power of Open Data
 
api_slides.pptx
api_slides.pptxapi_slides.pptx
api_slides.pptx
 
Getting Started with Public APIs
Getting Started with Public APIsGetting Started with Public APIs
Getting Started with Public APIs
 
Advanced Web Development in PHP - Understanding REST API
Advanced Web Development in PHP - Understanding REST APIAdvanced Web Development in PHP - Understanding REST API
Advanced Web Development in PHP - Understanding REST API
 
MuleSoft Surat Virtual Meetup#21 - MuleSoft API and RAML Design Best Practice...
MuleSoft Surat Virtual Meetup#21 - MuleSoft API and RAML Design Best Practice...MuleSoft Surat Virtual Meetup#21 - MuleSoft API and RAML Design Best Practice...
MuleSoft Surat Virtual Meetup#21 - MuleSoft API and RAML Design Best Practice...
 

Recently uploaded

FESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfFESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfMarinCaroMartnezBerg
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxolyaivanovalion
 
Brighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingBrighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingNeil Barnes
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptxAnupama Kate
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfLars Albertsson
 
Unveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data AnalystUnveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data AnalystSamantha Rae Coolbeth
 
Halmar dropshipping via API with DroFx
Halmar  dropshipping  via API with DroFxHalmar  dropshipping  via API with DroFx
Halmar dropshipping via API with DroFxolyaivanovalion
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysismanisha194592
 
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service BhilaiLow Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service BhilaiSuhani Kapoor
 
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptx
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptxBPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptx
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptxMohammedJunaid861692
 
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...Suhani Kapoor
 
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAl Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAroojKhan71
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz1
 
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改atducpo
 
Week-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionWeek-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionfulawalesam
 
Carero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxCarero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxolyaivanovalion
 
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfRachmat Ramadhan H
 

Recently uploaded (20)

VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...
VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...
VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...
 
FESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfFESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdf
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFx
 
Brighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingBrighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data Storytelling
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdf
 
Unveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data AnalystUnveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data Analyst
 
Halmar dropshipping via API with DroFx
Halmar  dropshipping  via API with DroFxHalmar  dropshipping  via API with DroFx
Halmar dropshipping via API with DroFx
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysis
 
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service BhilaiLow Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
 
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptx
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptxBPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptx
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptx
 
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
 
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAl Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signals
 
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in Kishangarh
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in  KishangarhDelhi 99530 vip 56974 Genuine Escort Service Call Girls in  Kishangarh
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in Kishangarh
 
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
 
Week-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionWeek-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interaction
 
Carero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxCarero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptx
 
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
 

Understanding APIs.pptx

  • 1. Understanding APIs How APIs and RESTful APIs work behind the scenes
  • 2. What is an API?
  • 3. 1 Application Programming Interface But not a “visual” interface like what we see in this presentation
  • 4. 1 It’s how one computer can talk to another computer. It doesn’t matter what programming language you’re using. JavaScript, Python, PHP, Java, C and every other modern language supports RESTful APIs. More on this in a bit...
  • 5. There are many types of APIs. But RESTful APIs are most commonly talked about these days.
  • 6. RESTful APIs are what we’re talking about today, too.
  • 7. Think of an API as a waiter as a restaurant. Art by iconicbestiary at https://www.freepik.com/iconicbestiary
  • 8. Art by iconicbestiary at https://www.freepik.com/iconicbestiary What can I get for you?
  • 9. Art by iconicbestiary at https://www.freepik.com/iconicbestiary Your finest pizza!
  • 10. The waiter relays the message to the kitchen. Art by iconicbestiary at https://www.freepik.com/iconicbestiary
  • 11. Where the chef makes the food. Art by freepik at https://www.freepik.com/freepik
  • 12. Then the waiter brings your food to you. Art by iconicbestiary at https://www.freepik.com/iconicbestiary
  • 13. It’s that simple! Just always keep this metaphor in mind. Remember the restaurant.
  • 14. RESTful APIs are meant to be simple.
  • 15. Let’s look at a real life example with actual computers.
  • 16. This is a site that uses an API to collect flight prices from other websites.
  • 19. Now you can see all the flight prices from other websites
  • 20. Computers use APIs to talk to each other over the internet.
  • 21. What programming languages can we use? Art by artmonkey at https://www.freepik.com/artmonkey
  • 22. What programming languages can we use? Art by artmonkey at https://www.freepik.com/artmonkey
  • 23. We can use any modern language that you’d use for a website. ● Python ● JavaScript ● PHP ● Java ● C ● Ruby ● Etc
  • 24. What are RESTful APIs? REST is a type of API Art by freepik at https://www.freepik.com/freepik
  • 26. Simply put: ● Client computer asks another computer for data, or to take an action
  • 27. SWAPI The Star Wars API https://swapi.co/
  • 28. JavaScript Demo fetch('https://swapi.co/api/people/') .then(res => res.json()) .then(response => console.log(response))
  • 29.
  • 32. Most languages have a data structure that looks like a JavaScript Object. One day, someone decided it should be a standard. Then it became the standard.
  • 33. Request Methods: ● HTTP GET ● HTTP POST ● HTTP PUT ● HTTP DELETE ● HTTP PATCH
  • 34. The first method: ● HTTP GET ● HTTP POST ● HTTP PUT ● HTTP DELETE ● HTTP PATCH
  • 36. GET Requests ● When you load a website. That’s a GET request ● It’s a request to get data from another computer ● You’re simply asking for data and you’re not asking to perform a task ● You’re not creating, updating or deleting data ● Most common request type
  • 37. HTTP Methods for RESTful Requests HTTP Method CRUD Operation Example URL(s) GET Read HTTP GET http://website.com/api/users/ HTTP GET http://website.com/api/users/1/
  • 39. POST Requests ● Do not go through the standard URL, but use a URL as the endpoint ● Ask another computer to create a new resource ● Returns data about the newly created resource
  • 40. HTTP Methods for RESTful Requests HTTP Method CRUD Operation Example URL(s) GET Read HTTP GET http://website.com/api/users/ HTTP GET http://website.com/api/users/1/ POST Create HTTP POST http://website.com/api/users/
  • 42. DELETE Requests ● Do not go through the standard URL, but use a URL as the endpoint ● Ask another computer to delete a single resource or a list of resources ● Use with caution
  • 43. HTTP Methods for RESTful Requests HTTP Method CRUD Operation Example URL(s) GET Read HTTP GET http://website.com/api/users/ HTTP GET http://website.com/api/users/1/ POST Create HTTP POST http://website.com/api/users/ DELETE Delete HTTP DELETE http://website.com/api/user/1/
  • 45. PATCH Requests ● Do not go through the standard URL, but use a URL as the endpoint ● Ask another computer to update a piece of a resource ● Are not fully supported by all browsers or frameworks, so we typically fall back on PUT requests ● Example: Updating a users first name
  • 46. PUT Requests ● Do not go through the standard URL, but use a URL as the endpoint ● Ask another computer to update an entire resource ● If the resource doesn’t exist, the API might decide to CREATE (CRUD) the resource
  • 47. HTTP Methods for RESTful Requests HTTP Method CRUD Operation Example URL(s) GET Read HTTP GET http://website.com/api/users/ HTTP GET http://website.com/api/users/1/ POST Create HTTP POST http://website.com/api/users/ DELETE Delete HTTP DELETE http://website.com/api/user/1/ PUT Update/Replace HTTP PUT http://website.com/api/user/1/ PATCH Partial Update/Modify HTTP PATCH http://website.com/api/user/1/ More details at https://restfulapi.net/http-methods/
  • 48. Consuming APIs Art by iconicbestiary at https://www.freepik.com/iconicbestiary
  • 49. APIs can be written in almost any server-side language. Art by starline at https://www.freepik.com/starline
  • 50. APIs will generally return one of two types data structures: JSON or XML Art by starline at https://www.freepik.com/starline
  • 51. JSON Example { "key_val_example": "value", "array_example": [ 'array item 1', 'array item 2', ], "object_example": { "key1": "value1", "key2": "value2" } } Art by starline at https://www.freepik.com/starline XML Example <example> <field> Value </field> <secondField> Value </secondField> <nestedExample> <nestedField> Value </nestedField> <nestedSecondField> Value </nestedSecondField> </nestedExample> </example>
  • 52. APIs can be consumed in almost any language. Art by starline at https://www.freepik.com/starline
  • 53. Browsers use JavaScript for their API requests. Servers use any language that runs on that computer. Art by starline at https://www.freepik.com/starline
  • 55. Requests and Responses When you request data from a server using GET, POST, PUT, PATCH or DELETE… that’s a request. When the server returns your data… that’s a response
  • 56. Requests and Responses Responses will always come with an HTTP Status Code. And these “status codes” tell you what’s wrong (or right) without needing to give you text back to read.
  • 57. Common HTTP Status Codes Healthy Responses (2--) ● 200 — OK. Request accepted. ● 201 — Created. POST requests often return 201s when a resource is created. ● 202 — Accepted. When a request is accepted but its not done processing. Maybe the task goes into a queue.
  • 58. Common HTTP Status Codes Redirect Responses (3--) ● 301 — Moved Permanently. When the endpoint has permanently changed. Update your endpoint. ● 302 — Found. The endpoint you’re accessing is temporarily moved to somewhere else.
  • 59. Common HTTP Status Codes Client Responses (4--) ● 400 — Bad Request. Server cannot or will not process your request. Often this is due to malformed API keys or an invalid payload. ● 401 — Unauthorized. You’re not allowed here. Usually this is because you’re missing authentication credentials (API keys) ● 403 — Forbidden. The servers understands your request but won’t execute it. Your API keys might not have the right permissions or your trying to use an endpoint that you don’t have access to. ● 404 — Not Found. There’s nothing here. Move along, move along. ● 405 — Method Not Allowed. You’re using the wrong HTTP Method. The endpoint might only accept GET requests and you might be POSTing to it, for example.
  • 60. Common HTTP Status Codes Server Responses (5--) ● 500 — Internal Server Error. The server had a problem and couldn’t process the request. This is the only time you are out of control.
  • 61. Just For Fun Find out what a 418 response is
  • 62. API Security Art by freepik at https://www.freepik.com/freepik
  • 63. API Keys ● API keys are “passwords” to access an API. These are your authentication credentials. ● Almost every website requires API keys to perform some action. ● Facebook's Graph API is a good example graph.facebook.com/codingforeverybody
  • 64. Access token required. Access tokens are usually generated with an API key. Matching 400 status code. “Bad Request”. Something is missing.
  • 65. Access token required. Access tokens are usually generated with an API key. Other services might throw you a 403 or 405 status.
  • 66. Art by Sapann Design at https://www.freepik.com/sapann-design Summary
  • 67. Think of an API as a waiter as a restaurant. Art by iconicbestiary at https://www.freepik.com/iconicbestiary
  • 68.
  • 69. HTTP Methods for RESTful Requests HTTP Method CRUD Operation Example URL(s) GET Read HTTP GET http://website.com/api/users/ HTTP GET http://website.com/api/users/1/ POST Create HTTP POST http://website.com/api/users/ DELETE Delete HTTP DELETE http://website.com/api/user/1/ PUT Update/Replace HTTP PUT http://website.com/api/user/1/ PATCH Partial Update/Modify HTTP PATCH http://website.com/api/user/1/
  • 70. Most APIs are secured with API keys Art by freepik at https://www.freepik.com/freepik
  • 71. Free Resources ● https://restfulapi.net/http-methods/ ● https://httpstatuses.com/ ● https://swapi.co/ Art by rawpixel.com at https://www.freepik.com/rawpixel-com
  • 72.