The document describes the API.
- Home Resources
- System Resources
- Users Resources
- Games Resources
- Media Types
- Request Details
- Response Details
- Navigation Graph
Gets the home resource, mainly with the primary (direct connected) and global (indirect connected) navigation links and actions. See Navigation Graph.
Request
- Method:
GET
- Path:
/api/
Response
- Success:
- Headers:
- Content-Type: "application/vnd.siren+json"
- Headers:
- Failure:
- Headers:
- Content-Type: "application/problem+json"
- Headers:
Gets the about resource, mainly with information about the current version of the system and information about the respective developers.
Request
- Method:
GET
- Path:
/api/system
Response
- Success:
- Headers:
- Content-Type: "application/vnd.siren+json"
- Headers:
- Failure:
- Headers:
- Content-Type: "application/problem+json"
- Headers:
Gets the current paged ranking of users, mainly with information on the total number of users and the statistics of each one on that page. Furthermore, there is a related link to each individual's user statistics.
Request
- Method:
GET
- Path:
/api/users/ranking
- [ Query
?page=__
]
Response
- Success:
- Headers:
- Content-Type: "application/vnd.siren+json"
- Headers:
- Failure:
- Headers:
- Content-Type: "application/problem+json"
- Headers:
Gets a user's statistics, mainly the number of games played, won, lost and tied.
Request
- Method:
GET
- Path:
/api/users/{userId}/statistics
Response
- Success:
- Headers:
- Content-Type: "application/vnd.siren+json"
- Headers:
- Failure:
- Headers:
- Content-Type: "application/problem+json"
- Headers:
Creates a user with necessary information.
Request
- Method:
POST
- Path:
/api/users
- Headers:
- Content-Type: "application/json"
- Body:
{ "username": text, "email": text, "password": text }
Response
- Success:
- Headers:
- Content-Type: "application/vnd.siren+json"
- Location
- Headers:
- Failure:
- Headers:
- Content-Type: "application/problem+json"
- Headers:
Create a temporary token for access to resources that require authorization.
Request
- Method:
POST
- Path:
/api/users/token
- Headers:
- Content-Type: "application/json"
- Body:
{ "identity": text, "password": text }
Response
- Success:
- Headers:
- Content-Type: "application/vnd.siren+json"
- Headers:
- Failure:
- Headers:
- Content-Type: "application/problem+json"
- Headers:
Gets a user's public information.
Request
- Method:
GET
- Path:
/api/users/{userId}
Response
- Success:
- Headers:
- Content-Type: "application/vnd.siren+json"
- Headers:
- Failure:
- Headers:
- Content-Type: "application/problem+json"
- Headers:
Invalidate a temporary token created for access to resources that require authorization.
Request
- Method:
POST
- Path:
/api/logout
- Headers:
Response
- Success:
- Headers:
- Content-Type: null
- Headers:
- Failure:
- Headers:
- Content-Type: "application/problem+json"
- Headers:
Gets a user's personal information and the links and actions within the account.
Request
- Method:
GET
- Path:
/api/me
- Headers:
Response
- Success:
- Headers:
- Content-Type: "application/vnd.siren+json"
- Headers:
- Failure:
- Headers:
- Content-Type: "application/problem+json"
- Headers:
Gets information of all supported variants.
Request
- Method:
GET
- Path:
/api/games/variants
- Headers:
Response
- Success:
- Headers:
- Content-Type: "application/vnd.siren+json"
- Headers:
- Failure:
- Headers:
- Content-Type: "application/problem+json"
- Headers:
Gets information for one of the supported variants.
Request
- Method:
GET
- Path:
/api/games/variants/{variantId}
- Headers:
Response
- Success:
- Headers:
- Content-Type: "application/vnd.siren+json"
- Headers:
- Failure:
- Headers:
- Content-Type: "application/problem+json"
- Headers:
Express a desire to start a game. There are two scenarios if it is successful. In the first scenario, the request was registered, i.e., as there is currently no other player waiting to play, the request is registered and it is possible to monitor the starting status of the game. In the second case the game was started, i.e., as there was a player waiting, the game could be started.
NOTE: The user who waited for the other user play with the black pieces (player b) and the user who joined the game will play with the white pieces (player w).
Request
- Method:
POST
- Path:
/api/games
- Headers:
- Authorization
- Content-Type: "application/json"
- [ Body: ]
{
"variantId": Int
}
Response
- Success:
- Headers:
- Content-Type: "application/vnd.siren+json"
- Headers:
- Failure:
- Headers:
- Content-Type: "application/problem+json"
- Headers:
Get the status of the game start monitor. There are two scenarios if it is successful, either the player continues waiting or someone has already joined.
Request
- Method:
GET
- Path:
/api/games/{gameId}/monitor
- Headers:
Response
- Success:
- Headers:
- Content-Type: "application/vnd.siren+json"
- Headers:
- Failure:
- Headers:
- Content-Type: "application/problem+json"
- Headers:
Give up waiting for other player.
Request
- Method:
DELETE
- Method:
/api/games/{gameId}/monitor
- Headers:
Response
- Success:
- Headers:
- Content-Type: null
- Headers:
- Failure:
- Headers:
- Content-Type: "application/problem+json"
- Headers:
Get current game status.
Request
- Method:
GET
- Path:
/api/games/{gameId}
- Headers:
Response
- Success:
- Headers:
- Content-Type: "application/vnd.siren+json"
- Headers:
- Failure:
- Headers:
- Content-Type: "application/problem+json"
- Headers:
Apply a move to a game.
Request
- Method:
PUT
- Path:
/api/games/{gameId}/play/row/{row}/column/{column}
- Headers:
Response
- Success:
- Headers:
- Content-Type: "application/vnd.siren+json"
- Headers:
- Failure:
- Headers:
- Content-Type: "application/problem+json"
- Headers:
Quit a game.
NOTE: Quitting a game means another game played and a game lost in the statistics.
Request
- Method:
PUT
- Path:
/api/games/{gameId}/giveup
- Headers:
Response
- Success:
- Headers:
- Content-Type: null
- Headers:
- Failure:
- Headers:
- Content-Type: "application/problem+json"
- Headers:
Media type for success responses according to Siren (Hypermedia).
Custom Action | Description |
---|---|
signup | Action to create a user. |
login | Action to create a temporary token to access resources that require authorization. |
logout | Action to inactivate a temporary token to access resources that require authorization. |
start-game | Action to express desire in starting a game. |
cancel | Action to cancel waiting for another user to start a game. |
play | Action to apply a move to a game. |
give-up | Action to quit a game. |
NOTE: The remaining link relations used are described in IANA - Link Relations.
Example of a response with media type application/vnd.siren+json:
{
"class": [
"game"
],
"properties": {
"gameState": "NEXT_TURN_B",
"playerB": 1,
"playerW": 2,
"playingRoundTime": "5m",
"pieces": [],
"variantId": 1
},
"links": [
{
"rel": [
"self"
],
"href": "/api/games/ff0d5e34-8c28-49dd-9c0e-6ceafbf9934b",
"authenticationType": [
"BEARER",
"COOKIE"
]
},
{
"rel": [
"https://github.com/isel-leic-daw/2023-daw-leic51d-07/tree/main/docs/api/rel/variant"
],
"href": "/api/games/variants/1",
"authenticationType": [
"BEARER",
"COOKIE"
]
}
],
"entities": [],
"actions": [
{
"name": "play",
"title": "Make a move",
"href": "/api/games/{id}/play/row/{row}/column/{column}",
"method": "PUT",
"authenticationType": [
"BEARER",
"COOKIE"
],
"fields": []
},
{
"name": "give-up",
"title": "Give up on game",
"href": "/api/games/ff0d5e34-8c28-49dd-9c0e-6ceafbf9934b/giveup",
"method": "PUT",
"authenticationType": [
"BEARER",
"COOKIE"
],
"fields": []
}
]
}
Media type for body requests type according to RFC 4627.
Media type for failure responses according to RFC 7807.
Example of a response with media type application/problem+json:
{
"type": "https://github.com/isel-leic-daw/2023-daw-leic51d-07/tree/main/docs/api/problem/gameNotFound",
"title": "Game not found.",
"detail": "Game with id 'ff0d5e34-8c28-49dd-9c0e-06ceafbf9934' not found."
}
Path field | Type | Description |
---|---|---|
userId | number | User identifier. |
gameId | number | Game identifier. |
variantId | number | Variant identifier. |
row | number | Board row where you want to play. The first position in the row is 0 and last is boardDim - 1 of the chosen game variant. |
column | number | Board column where you want to play. The first position in the column is 0 and last is boardDim - 1 of the chosen game variant. |
Query field | Type | Description |
---|---|---|
page | number | Optional intended page in paginated resources. |
Body fields | Type | Description |
---|---|---|
username | text | Descriptive text about the desired username for the user. The field can not be empty and is required. |
text | Descriptive text about the desired email for the user. The field must match a valid email format, i.e., it must have exactly one @ character and at least one . character. The field can not be empty and is required. | |
password | text | Descriptive text about the desired password for the user. The field must have security requirements, i.e., it must have at least 6 characters, at least one digit, at least one lowercase letter and at least one uppercase letter. The field can not be empty and is required. |
identity | text | Descriptive text about user identification of a user. The field may correspond to the username or email indicated when creating the user. The field can not be empty and is required. |
variantId | number | Descriptive number about the desired game variant. The field is optional. |
Class value | Type | Description |
---|---|---|
home | text | Home entity represents primary navigation links. |
system-info | text | System-Info entity represents information about system, namely system version. |
system-authors | text | System-Authors entity represents information about the developers of the current version of the API. |
ranking | text | Ranking entity represents the current ranking of users' scores. |
user | text | User entity represents the public information of a user. |
statistics | text | Statistics entity represents the current statistics of requested user. |
authorization | text | Authorization entity represents user authentication for authenticated resource access. |
user-home | text | User Home entity represents the user's personal information and the links and actions within the account. |
variant | text | Variant entity represents information of one supported variants. |
variants | text | Variants entity represents information of all supported variants. |
monitor | text | Monitor entity represents the state monitoring "object" while the game is not starting. |
game | text | Game entity represents the game. |
Property name | Property value | Type | Description |
---|---|---|---|
welcome | - | text | Welcome message. |
version | - | text | Current version of system, in Semantic-versioning scheme. |
createdAt | - | text | Current system version creation date. |
authors | - | array | Current system version authors. |
firstName | - | text | Author's first name. |
surname | - | text | Author's surname. |
- | text | Author's or User's email. | |
userId | - | number | User identifier. |
user-{userI}-statistics | - | text | The related statistics for user . |
username | - | text | User username. |
totalUsers | - | number | The current total number of users. The value 0 represents that there is no user. |
token | - | string | Temporary token for access to resources that require authorization. |
expiration | - | string | Token expiration date and time. |
rankingPosition | - | number | Current position occupied in the ranking. |
gamesPlayed | - | number | Number of games played by the user. The value 0 represents that the player has not played any games yet. |
gamesWon | - | number | Number of games won by the user. The value 0 represents that the player has not won any games yet. |
gamesLost | - | text | Number of games lost by the user. The value 0 represents that the player has not lost any games yet. |
gamesTied | - | text | Number of games tied by the user. The value 0 represents that the player has not tied any games yet. |
variants | - | array | Current supported game variants. A variant is a set of boardDim, openingRules and playingRules. |
variantId | - | number | Variant identifier. |
boardDim | - | number | The size of game board is boardDim * boardDim. |
openingRules | 1 - NONE | text | 1 - There are no specific opening rules. |
playingRules | 1 - FREESTYLE | text | 1 - The standard game without specific gameplay rules. |
status | 1 - WAITING_FOR_OTHER_PLAYER 2 - OTHER_PLAYER_JOINED |
text | 1 - Waiting state for another player to start the game. 2 - Terminal state given that another player has already joined and the game has started. |
askAgainIn | - | text | Recommended time (in seconds) to monitor the status once again or 'null' if no longer needed. |
gameState | 1 - NEXT_TURN_W 2 - NEXT_TURN_B 3 - WINNER_W 4 - WINNER_B 5 - DRAW |
text | 1 - It's the white player's turn. 2 - It's the black player's turn. 3 - The game is over and the white player has won. 4 - The game is over and the black player has won. 5 - The game is over and tied. |
playerB | - | text | The identifier of the user who is playing with the black pieces in the current game. |
playerW | - | text | The identifier of the user who is playing with the white pieces in the current game. |
playingRoundTime | - | text | The time to play the round (in minutes). |
pieces | - | array | All the pieces present on the game board, where each piece corresponds to a player and an intersection. |
player | 1 - B 2 - W |
text | 1 - Player with the black pieces 2 - Player with the white pieces. |
intersection | - | object | Intersection is the position corresponding to a row and a column. |
row | - | number | Board row. The first position in the row is 0 and last is boardDim - 1 of the chosen game variant. |
column | - | number | Board column. The first position in the column is 0 and last is boardDim - 1 of the chosen game variant. |
Field name | Field value | Description |
---|---|---|
authenticationType | 1 - NONE 2 - BEARER 3 - COOKIE |
1 - The subsequent request does not require authentication to be performed. 2 - The subsequent request requires authentication to be executed, it requires the inclusion of the authentication header in the HTTP request with the bearer token. 3 - The subsequent request requires authentication to be executed, it requires the inclusion of the cookie header in the HTTP request with the token. |
The following graph corresponds to the supported navigation graph.