]> git.cworth.org Git - empires-api/blob - tictactoe.txt
Add a new game-info event
[empires-api] / tictactoe.txt
1 Tic Tac Toe Game Protocol
2 =========================
3 Note: All square numbers in the protol below are as follows:
4
5         0|1|2
6         -+-+-
7         3|4|5
8         -+-+-
9         6|7|8
10
11 For a specific game the following API endpoints are defined.
12 (Note: Only the trailing portion of the API URI is provided here.
13  The preceding portions of the path must be determined externally.)
14
15 /events
16
17     This is a server-sent events stream that allows the server to push
18     game-related events to clients. When a client connects to this API
19     endpoint the server will return a header that includes:
20
21         Content-type: text/event-stream
22         Connection: keep-alive
23         Cache-Control: no-cache
24
25     and will keep the connection open to return events.
26
27     The following event types will be returned by the server:
28
29         TYPE: game-info
30
31         WHEN: When a client first connects
32
33         WHAT: Static information about the game (will not change)
34
35         EXAMPLE:
36
37                 event: game-info
38                 data: {"id":"WXYZ","url":"https://lmno.games/WXYZ"}
39
40         TYPE: game-state
41
42         WHEN: When a client first connects
43
44         WHAT: Snapshot of the current dynamic game state
45
46         EXAMPLE:
47
48                 event: game-state
49                 data: {"moves":[0,8],"board":["X","","","","","","","","O"],"next_player":"X"}
50
51         TYPE: move
52
53         WHEN: When a client (maybe yourself) issues a legal move
54
55         EXAMPLE:
56
57                 event: move
58                 data: 4
59
60 /move
61
62     Method: POST
63
64     Behavior: Adds a new move to the game
65
66     Example data: { "move": 1 }