Version: 2.1
Last Updated: September 2026
JGame provides a high-performance RESTful API for user authentication, game catalog discovery, real-time lobbies, ratings, user profiles, and persistent leaderboards. The server is built with Javalin 6 and uses JWT (HMAC-SHA256) for stateful token validation and revocation.
http://localhost:8080/api
POST /api/auth/register
Content-Type: application/json
{
"username": "player1",
"password": "Password123!",
"email": "player1@example.com"
}Response (201 Created):
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"username": "player1"
}POST /api/auth/login
Content-Type: application/json
{
"username": "player1",
"password": "Password123!"
}Response (200 OK):
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"username": "player1"
}Revokes the active JWT token and registers it in the server-side TokenBlacklist.
POST /api/auth/logout
Authorization: Bearer <token>Response (200 OK):
{
"message": "Logged out successfully"
}Include the token in the Authorization header for protected endpoints:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...GET /api/user/profile
Authorization: Bearer <token>Response (200 OK):
{
"userId": "1",
"username": "player1",
"role": "user"
}PUT /api/user/profile
Authorization: Bearer <token>
Content-Type: application/json
{
"email": "newemail@example.com",
"password": "NewPassword123!"
}Response (200 OK):
{
"message": "Profile updated successfully"
}GET /api/user/scores
Authorization: Bearer <token>Response (200 OK):
[
{
"userId": "player1",
"gameId": "chess",
"points": 1250,
"gamesPlayed": 23,
"wins": 15,
"losses": 8,
"totalTime": "PT1H30M",
"lastPlayed": "2026-09-15T10:00:00Z"
}
]GET /api/games?sort=name&q=chessResponse (200 OK):
[
{
"id": "chess",
"name": "Chess",
"version": "1.0",
"author": "JGame",
"description": "Classic chess game",
"rules": "Standard chess rules",
"minPlayers": 2,
"maxPlayers": 2,
"metadata": {}
}
]GET /api/games/{gameId}GET /api/games/{gameId}/ratingsResponse (200 OK):
{
"ratings": [
{
"userId": "player1",
"gameId": "chess",
"stars": 5,
"comment": "Superb implementation!",
"createdAt": "2026-09-15T09:30:00Z",
"updatedAt": "2026-09-15T09:30:00Z"
}
],
"average": 4.8,
"count": 12
}Comments are sanitized automatically against HTML/script injection.
POST /api/ratings/{gameId}
Authorization: Bearer <token>
Content-Type: application/json
{
"stars": 5,
"comment": "Great strategic depth!"
}DELETE /api/ratings/{gameId}
Authorization: Bearer <token>GET /api/scores/{gameId}/leaderboard?limit=10Response (200 OK):
[
{
"userId": "grandmaster",
"gameId": "chess",
"points": 2500,
"gamesPlayed": 45,
"wins": 40,
"losses": 5
}
]| Status Code | Description |
|---|---|
200 OK |
Request succeeded |
201 Created |
Resource created |
204 No Content |
Action succeeded with no body |
400 Bad Request |
Validation failure or malformed payload |
401 Unauthorized |
Missing, invalid, or revoked JWT token |
404 Not Found |
Requested game, rating or resource not found |
409 Conflict |
Username already registered |
429 Too Many Requests |
Rate limit exceeded (brute-force defense) |
500 Internal Server Error |
Unhandled server error |
Standard Error Format:
{
"error": "Error description message"
}GameApiClient client = new GameApiClient("http://localhost:8080");
client.login("player1", "Password123!").thenAccept(res -> {
System.out.println("Logged in with token: " + res.token());
});const api = new JGameAPI("http://localhost:8080");
await api.login("player1", "Password123!");
const games = await api.getGames();