The first player to join will be X; the second player to join will be O.
Live Endpoint: http://tictactoe.devdogsuga.org/
Creates a new TicTacToe game.
- Returns a JSON response on
200 Success
Successful Response Shape:
{
"gameCode": string,
"playerId": string
}Gets a new player id for a TicTacToe game with game code [gameCode].
- Returns a JSON response on
200 Success - Returns
400 Bad Requestif game already has two players - Returns
404 Not Foundif game doesn't exist
Successful Response Shape:
{
"playerId": string
}Join a new game via a WebSocket connection.
- Returns
101 Switching Protocolson success - Returns
401 Unauthorizedif player id is incorrect - Returns
404 Not Foundif game doesn't exist
After joining the game, the following JSON messages are supported to be recieved by the server:
Required to be sent upon recieving a ping
{
"type": "pong"
}Play a move a the provided index (0-8) for the connected player
{
"type": "move",
"data": number
}Set the rematch flag for the currently connected player.
{
"type": "move",
"data": number
}Sent every 30 seconds to check if the connection is still alive
{
"type": "ping",
"data": number
}Sent every time the game state changes (i.e., a player connections/disconnects, a player commits a move, or a player requests a rematch)
{
"type": "state",
"data": {
"turn": "X" | "O",
"connected": {
"playerX": boolean,
"playerO": boolean
},
"rematch": {
"playerX": boolean,
"playerO": boolean
},
"board": [
"X" | "O" | null,
"X" | "O" | null,
"X" | "O" | null,
"X" | "O" | null,
"X" | "O" | null,
"X" | "O" | null,
"X" | "O" | null,
"X" | "O" | null,
"X" | "O" | null
]
}
}