This microservice handles the persistent storage and retrieval of a player's game state progress. It provides a REST API over HTTP for storing and retrieving progress data in order to load to game by using optional save slots or autosave.
- Python 3 and Flask.
git clone https://github.com/NKayla/save-load-microservice.git
cd save-load-microservice
Install dependencies
pip install flask
python service.py
- Run server.py
- Test with browser in separate terminal.
python test_client.py
gameIdUnique Id for game.playerIdUnique Id for player.slotIdUnique Id for save slot assigned to player. (Query parameter)
Data is sent and received as JSON. Examples:
- levelsCompleted [array of integers]
- coins [int]
- upgrades [boolean]
Saving the game state (player progress) - send data to server.
- Method: POST
- Endpoint:
/games/{gameId}/players/{playerId}/save?slotId=slot2 - URL to call endpoint (local dev): http://localhost:5000
- Content-Type: application/json
- Status Codes: 201 Created, 400 Bad Request
Example JSON Body:
{
"levelsCompleted": [1, 2, 3],
"health": 90,
"coins": 320,
"upgrades": {
"locked": false,
"unlocked": true
}import requests
# save progress
response = requests.post(
"http://127.0.0.1:5000/games/game1/players/player81/save",
params={"slotId: "default"},
json={"levelCompleted": 5, "coins": 350}
}
print("Status", response.status_code)
print("Body":, response.json())
Retrieve the player's progress from service.
- Method: GET
- Endpoint:
/games/{gameId}/players/{playerId}/save?slotId=slot2 - URL to call endpoint (local dev): http://localhost:5000
- Status Codes: 200 Ok, 404 Not Found
Example
import requests
response = requests.get(
"http://127.0.0.1:5000/games/game1/players/player81/save",
params={"slotId: "default"}
}
print("Status", response.status_code)
print("Body":, response.json())
Response body example (game client receives):
{
"levelsCompleted": [1, 2, 3],
"health": 90,
"coins": 320,
"upgrades": {
"locked": false,
"unlocked": true
}Autosave used in game to save at checkpoints. Method: POST
- Autosave is controlled by the game client.
- Normal http request.