API = Application Programming Interface
Note
Interface between two computers or two programs.
It is an application that provides services to other applications.
The application implements an API or exposes an API.
A fairly broad term that covers:
Note
An API provides a service to users without them needing to know how it works. They only know what it expects as input and what it produces!
A specific type of API.
In your opinion, does X allow everyone to directly access their databases?
Involves writing an application that:
Problems:
Interface between the outside and our system
Note
A web service is an application module, accessible over the HTTP protocol via a URL that will respond to a request
➡️ Like a website, but for machines
E-commerce site:
Note
Useful for large companies with many developers and parallel projects.
Client-server communication protocol developed for the World Wide Web
Not the only one: FTP, SMTP, IRC…
There are non-client-server protocols: BitTorrent
Secure connection between a client and a server:
GET https://pokeapi.co/api/v2/pokemon?limit=10&offset=200
Important
C’est le CRUD !
A tool: an HTTP client
requests pluginimport requests
# Building the request
url = "https://data.rennesmetropole.fr/api/records/1.0/search/"
parameters = {"dataset": "etat-du-trafic-en-temps-reel", "rows": 2}
# Launching the request
res = requests.get(url=url, params=parameters)
# Displaying the result
print(res.json())
print("\nNumber of rows: ", res.json()["parameters"]["rows"])import json
import requests
url = "https://anapioficeandfire.com/api/"
end_point = "characters"
parameters = {"gender": "Female", "isAlive": True, "culture": "Braavosi"}
response = requests.get(url=url + end_point, params=parameters)
# Check if the server responded
if response.status_code != 200:
raise Exception(f"Cannot reach (HTTP {response.status_code}): {response.text}")
print(json.dumps(response.json()))res.json() returns a dictionaryget() can become post(), put(), etc.