Úvod do API v Pythonu
Chris Ramakers
Engineering Manager
http://350.5th-ave.com/unit/243

# Append the query parameter to the URL string
response = requests.get('http://350.5th-ave.com/unit/243?floor=77&elevator=True')
print(response.url)
http://350.5th-ave.com/unit/243?floor=77&elevator=True
params slouží k přidání parametrů dotazu# Create dictionary
query_params = {'floor': 77, 'elevator': True}
# Pass the dictionary using the `params` argument
response = requests.get('http://350.5th-ave.com/unit/243', params=query_params)
print(response.url)
http://350.5th-ave.com/unit/243?floor=77&elevator=True
http://350.5th-ave.com/unit/243| Sloveso | Akce | Popis |
|---|---|---|
| GET | Čtení | Zkontrolovat obsah poštovní schránky |
| POST | Vytvoření | Vložit nový balíček do schránky |
| PUT | Aktualizace | Nahradit všechny balíčky novým |
| DELETE | Smazání | Odebrat všechny balíčky ze schránky |
# GET = Retrieve a resource response = requests.get('http://350.5th-ave.com/unit/243')# POST = Create a resource response = requests.post('http://350.5th-ave.com/unit/243', data={"key": "value"}) # PUT = Update an existing resource response = requests.put('http://350.5th-ave.com/unit/243', data={"key": "value"})# DELETE = Remove a resource response = requests.delete('http://350.5th-ave.com/unit/243')
requestsdata slouží k předání dat v požadavku POST nebo PUT.Úvod do API v Pythonu