]> git.cworth.org Git - empires-api/blob - api.text
Add a version indication to the protocol description
[empires-api] / api.text
1 Empires Game Protocol
2 =====================
3 Version: 0.3
4
5 For a specific game the following API endpoints are defined.
6 (Note: Only the trailing portion of the API URI is provided here.
7  The preceding portions of the path must be determined externally.)
8
9 /events
10
11     This is a server-sent events stream that allows the server to push
12     game-related events to clients. When a client connects to this API
13     endpoint the server will return a header that includes:
14
15         Content-type: text/event-stream
16         Connection: keep-alive
17         Cache-Control: no-cache
18
19     and will keep the connection open to return events.
20
21     The following event types will be returned by the server:
22
23         TYPE: players
24
25         WHEN: When a client first connects
26
27         PURPOSE: Describes all players in the game already
28
29         EXAMPLE:
30
31                 event: players
32                 data: [{"id":1,"name":"Carl"},{"id":2,"name":"Kevin"}]
33
34         TYPE: player-join
35
36         WHEN: When a player joins the game
37
38         EXAMPLE:
39
40                 event: player-join
41                 data: {"id":3,"name":"Richard"}
42
43         TYPE: player-leave
44
45         WHEN: When a player leaves the game
46
47         EXAMPLE:
48
49                 event: player-leave
50                 data: {"id":3}
51
52         TYPE: capture
53
54         WHEN: When one player captures another
55
56         EXAMPLE:
57
58                 event: capture
59                 data: {"captor": 2, "captee": 1}
60
61 /register
62
63     Method: POST
64
65     Behavior: Adds a new player with "name" and "character" and assigns an id. Also will add a new empire with empty "captured" array
66
67     Example data: { "name": "Carl", "character: "Elvis" }
68
69 /deregister/<ID>
70
71     Method: POST
72
73     Behavior: Removes an existing player with the given ID
74
75 /reset
76
77     Method: POST
78
79     Behavior: Removes all players (bulk deregister)
80
81 /restart
82
83     Method: POST
84
85     Behavior: Eliminates all current empire ownership so the existing
86     players can start a new game
87
88 /capture/<ID1>/<ID2>
89
90     Method: POST
91
92     Behavior: Indicate that empire ID1 has now captured ID2
93
94 /liberate/<ID>
95
96     Method: POST
97
98     Behavior: Indicate that empire ID is no longer captured (undoing a
99     previous /capture)
100
101 /characters
102
103     Method: GET
104
105     Behavior: Returns a lists of all character names (in alphabetical order)
106
107     Example data: [ "Einstein", "Elvis", "Fred Flintstone" ]
108
109 /empires
110
111     Method: GET
112
113     Behavior: Shows which empires have been captured by other empires
114
115     Example data [ { "id": 1, "captures": [] },
116                    { "id": 2, "captures": [1] },
117                    { "id": 3, "captures": [4, 5, 6] },
118                    { "id": 4, "captures": [2] },
119                    { "id": 5, "captures": [] },
120                    { "id": 6, "captures": [] } ]
121
122 /players
123
124     Method: GET
125
126     Behavior: Gets a list of all the player objects (without their
127     character names)
128
129     Example data: [ { id: 1, name: "Carl" }, { id: 2, name: "Kevin" } ]
130
131 Server
132 ======
133 There's a sample server available at: https://families.cworth.org/api/
134
135 We plan to move this to https://empires.cworth.org at some point.