Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A very simple example python program to read (imagined) high scores and post high scores from/to a Web API.
# Quickstart:
import requests # For HTTP requests (GETting and POSTing stuff)
import random # we'll generate some random data for speed
# you can look at the scores on the server here:
# You can make your OWN server by remixing my one. Start here:
# server_base = ""
server_base = ""
sample_usernames = ['Grace', 'Neill', 'Nicholas', 'Nishka', 'Imran',
'Femi', 'Mutsa', 'Thomas', 'Alex', 'Oscar']
def get_scores():
URL = server_base + "/scores"
response = requests.get(url=URL)
return response.json()
def post_new_score(score, username):
URL = server_base + "/scores"
dictToPost = {'score': score, 'username': username}
response =, json=dictToPost)
data = response.json()
return data
print("Current scores")
# WARNING: Do NOT spam my server by sending hundreds of requests, please!
print("Posting a few random scores...")
for i in range(3):
username = random.choice(sample_usernames)
score = random.randint(1, 999)
response = post_new_score(score, username)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.