Space Game API
All endpoints are prefixed with /api.
Endpoints marked JWT require a
Bearer token in the Authorization header.
Authentication
Creates a new user account. Returns a JWT token for use with authenticated endpoints.
{
"username": "newuser",
"password": "securepassword123"
}
{ "token": "eyJhbGci..." }
{ "message": "User already exists" }
Authenticates an existing user and returns a JWT token.
{
"username": "existinguser",
"password": "securepassword123"
}
{ "token": "eyJhbGci..." }
{ "message": "Invalid credentials" }
Game Assets & UI
Returns a randomly generated hex color code for use in UI elements.
{ "color": "#A34FBC" }
Serves the main background image from assets/background.jpg.
// Content-Type: image/jpeg
Serves the background music file from assets/music.mp3.
// Content-Type: audio/mpeg
Returns URLs to all available SVG skins — spaceship, asteroid, and UFO.
{
"spaceship": "…/Ship_Mk1.svg",
"asteroid": "…/SpaceRock.svg",
"ufo": "…/AlienInvader.svg"
}
Retrieves a specific SVG asset by filename.
| Parameter | Type | Description |
|---|---|---|
| skinName | string | SVG filename, e.g. Ship_Mk1.svg
|
// Content-Type: image/svg+xml
{ "message": "Skin not found." }
Returns an array of normalized 2D coordinates [x, y] for asteroid spawn
positions.
{
"layout": [
[0.12, 0.85],
[0.54, 0.23],
// ...
]
}
Returns two unique random power-ups after clearing a wave. Requires a valid JWT token.
{
"waveCleared": true,
"waveNumber": 5
}
[
{
"id": 1,
"name": "Deflector Shield",
"description": "Absorbs one fatal hit",
"duration": -1
},
{
"id": 3,
"name": "Chrono-Matrix",
"description": "Slows asteroids 50%",
"duration": 15000
}
]
{ "message": "waveCleared must be true" }
Leaderboard
Returns the top 10 highest scores, ordered by score descending.
[
{
"id": 1,
"username": "playerOne",
"score": 15000,
"CreatedAt": "2023-10-27T10:00:00Z"
},
// ...
]
Submits a player's score. If the user already has an entry, it's updated only when the new score is higher.
{
"name": "AuthenticatedUser",
"score": 20000
}
{ "message": "Score updated successfully" }