0% found this document useful (0 votes)
0 views14 pages

How The Internet Works

The document explains how the internet works, focusing on the process of requesting resources and the concept of APIs. It outlines how to query APIs using Python, including sample requests and the structure of API calls. The document emphasizes the importance of understanding parameters and authentication when interacting with APIs.

Uploaded by

Leonardo Bertati
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)
0 views14 pages

How The Internet Works

The document explains how the internet works, focusing on the process of requesting resources and the concept of APIs. It outlines how to query APIs using Python, including sample requests and the structure of API calls. The document emphasizes the importance of understanding parameters and authentication when interacting with APIs.

Uploaded by

Leonardo Bertati
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
You are on page 1/ 14

How The Internet

Works
Learning Goals

● Develop a mental model of how the internet works


● Understand what it means to request a resource over the internet
● Understand what an API is
● Understand how to query APIs in Python
How do we get the news?

What
's the
h eadlin
e toda
"Mexica y?
ns Aw
ait Re
sults i
to Firs n Elec
t Fema tion E
le Pre xpecte
sident d to Le
" ad

?
ovies section
a d li ne in the m
he h e
What's t
levate
u n gry to E
aker H lls"
i an Filmm Thri
"A Nig
e r
o l l y wood’s
N
Inspecting these interactions

What's the headline today?

"Mexicans Await Results in Election Expected to Lead


to First Female President"

This is like a
This is like a function call
return value
Inspecting these interactions

This is like a
parameter

What's the headline in the movies section?

"A Nigerian Filmmaker Hungry to Elevate


Nollywood’s Thrills"

This is like a
This is like a function call
return value
What would that function look like?

def get_headline(search)

get_headline({}) get_headline({"section": "movies"})


What would that function look like?

This is an API, or Application Programming Interface

def get_headline(search)

Instructions for calling get_articles

* The search parameter should be a dictionary


* If 'search' has a 'section' key/value pair, get the
headline for that section
* If 'search' has a 'date' key/value pair, get the headline
for that date. Otherwise, get the deadline today
* If 'search' has a 'language' key/value pair, get the
headline for that language
* …
Understanding APIs

Instead of calling functions, we query URLs

GET www.nytimes.com/headlines?<search>
Understanding APIs

Instead of calling functions, we query URLs

GET www.nytimes.com/headlines?<search>

'GET' means that you want to


fetch something from an API
Understanding APIs

Instead of calling functions, we query URLs

GET www.nytimes.com/headlines?<search>

This is the API URL, which


identifies the information you
want
Understanding APIs

Instead of calling functions, we query URLs

GET www.nytimes.com/headlines?<search>

These are parameters for your


query
Sample requests

GET www.nytimes.com/headlines
Get the current headline of the New York Times

GET www.nytimes.com/headlines?section=movies
Get the current headline of the movies section of New York Times

POST www.nytimes.com/comments
Make a comment on an article
How does an API know who you are?

Ok! Whenever you


query me, give me
the secret number
I want to query 42 so I know you're
your API! allowed to make
requests

GET www.nytimes.com/headlines?api_key=42&section=movies
So, how do we do
this in Python?
import requests

You might also like