Any questions?
Project reviews
You
What caught your attention this week?
An API defines
In other terms : an API allows apps to talk to each other.
In safari and other browsers, the full URL is hidden.
In the finder, go to settings
» advanced
enable the “Show full website address
” option.
A URL (Uniform Resource Locator) is the address of a unique resource on the internet.
domain name + everything else to specify the data you requested
https://{domain name}/{endpoint}?{params}
Example :
https://skatai.com//inwai/api/#slide-9
The REST protocol is a set of rules that define how applications can interact with each other.
The whole digital economy is based on these 4 words!
example on instagram, bluesky, X, facebook, tiktok, etc.
and every other website
The Web is One BIG API + GET requests
It uses URLs to send requests to a server
The server sends the html page back
You should end up on this URL:
https://www.goodreads.com/author/show/58.Frank_Herbert
https://www.goodreads.com/author/**show**/58.Frank_Herbert
which can be read as: show an author, with label 58.frank.herbert
Now scroll down and click on “More Books by Frank Herbert”
The URL is now https://www.goodreads.com/author/list/58.Frank_Herbert
The verb “/show” is replaced with the verb “/list”.
Now click on page 2, the URL becomes
https://www.goodreads.com/author/list/58.Frank_Herbert?page=2&per_page=30
which reads
An endpoint: an URL
and a path
some optional parameters: ?page=2&per_page=30
A method : GET the content, PUT or POST new content, DELETE the content
The data in JSON format as the server response, or just plain text, html, pdfs, csv, audio, video etc
go on a social network or a website
Grab a screenshot of the Devtools screen, network tab
Paste in a LLM like chatGPT or Claude or …
ask: explain in simple terms what I’m seeing
We can use the API front end (sandbox) to play with the API but as we can see it’s not trivial
So we need to read :
Best to check out
# Do a Wikipedia search for query.
wikipedia.search(query, results=10, suggestion=False)
https://pypi.org/project/Wikipedia-API/
First install the library : !pip install wikipedia-api
Note the !
before pip
.
Then we look at some code
import wikipediaapi
# Initialize Wikipedia API (English)
wiki_wiki = wikipediaapi.Wikipedia( user_agent="[email protected]", language='en')
# Get the page : the actual request to the API
page = wiki_wiki.page("Paris")
# Check if the page exists
if page.exists():
print(f"Title: {page.title}\n")
print(f"Summary: {page.summary[:500]}...") # print first 500 chars of summary
else:
print("Page not found.")
pass all the parameters to specify how how want to interact with the object
wiki_wiki = wikipediaapi.Wikipedia( user_agent="[email protected]", language='en')
wiki_wiki
is the object that we use to interact with the API. It has now been initialized, or instanciated
Also pass all the required identification parameters (login, password, API key, …). Not needed for wikipedia API.
print("Hello world")
my_var = "Hello world"
print(my_var)
my_var = "Hello world"
print(f"Title: {my_var}\n")
notice :
f
before the string{}
around the variable\n
at the end of the string.\n
is the line return character"My name is Spiderman"
hero
with the value "Spiderman"
hero
"Hero:"
followed by the variable hero
(concatenation)quote = "With great power comes great responsibility"
A method call : notice the ()
page.exists()
A property on the object page
: no ()
page.title
Now in google colab
page
object has besides title and summary["Paris", "New York", "Tokyo", "London", "Berlin"]
)In-depth reporting and analytical commentary on artificial intelligence regulation.