Skip to content

Instantly share code, notes, and snippets.

@Trafitto
Last active September 23, 2019 16:47
Show Gist options
  • Save Trafitto/8b3ca2b28824b742a115007a6568d974 to your computer and use it in GitHub Desktop.
Save Trafitto/8b3ca2b28824b742a115007a6568d974 to your computer and use it in GitHub Desktop.
import requests
BASE_URL = "http://bestemmie.org/api/{endpoint}"
# GET ALL BESTEMMIE
# ENDPOINT: /bestemmie
'''
Method: GET
Optional params:
offset (default 50)
limit (default 50)
Response field:
count: total distinct count of bestemmie
next: the url to the next page
previous: the url to the previous page
results: array of bestemmie with the single count of how many time was inserted
Response example:
{
"count": 984,
"next": "http://bestemmie.org/api/bestemmie/?limit=50&offset=50",
"previous": null,
"results": [
{
"bestemmia": "DIO CANE",
"count": 2
},
...
]
}
'''
response = requests.get(BASE_URL.format(endpoint="bestemmie"))
response.raise_for_status()
print(response.json()['results'])
'''
[ {'count': 2, 'bestemmia': u'DIO CANE'}, ...]
'''
# ADD BESTEMMIA
# ENDPOINT: /bestemmie/
'''
Method: POST
*notice, the endpoint ends with "/"
'''
params = {
"bestemmia": "Dio cane"
}
response = requests.post(BASE_URL.format(endpoint="bestemmie/"), params)
response.raise_for_status()
'''
Return 204 no content
'''
# GET RANDOM BESTEMMIA
# ENDPOINT: /random
'''
Method: GET
Response example:
{
"bestemmia": "DIO CANE",
"count": 2
}
'''
response = requests.get(BASE_URL.format(endpoint="random"))
response.raise_for_status()
print(response.json())
'''
{'count': 1, 'bestemmia': u'DIO CANE'}
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment