From 0da8098559b7134c090d8ed58d61d145a9310211 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Mon, 5 Apr 2021 18:53:19 +0200 Subject: partial api docs move :tada: --- api/readme.md | 487 +++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 447 insertions(+), 40 deletions(-) (limited to 'api') diff --git a/api/readme.md b/api/readme.md index 26ef02b..70aeaf5 100644 --- a/api/readme.md +++ b/api/readme.md @@ -6,51 +6,458 @@ This is the subdirectory for the API. You can find the API reference in [this](h API return type classes are mostly defined in api/api.ts -endpoint|method|description|parameters|authorization --|-|-|-|- -/status | GET | get online user count and active game count -/auth/login | POST | log in with email or username -/auth/token | POST | log in using a token (stored as cookie) -/auth/signup | POST | sign up -/user/info | GET\|POST | get user info by username or id note: avatar is a uri to a 256x256 .png image -/user/games | GET\|POST | get games of user -/user/avatar | GET\|POST | fetch or update avatar note: avatar is a client-resized 256x256 .png base64-encoded image, request returns error when image is not .png or larger than 256x256 -/user/prefrences | GET\|POST | fetch or change user preferences -/user/password | POST | update password -/user/email | POST | update email (token used for authentication if password is undefined) -/user/username | POST | update username (token used for authentication if password is undefined) -/user/status | POST | update status -/user/searchFriends | POST | search user's friend list -/social/request | POST | send a friend request to a user by user id -/social/accept | POST | accept a friend request -/social/remove | POST | remove a friend from your friend list or delete a friend request from a user -/social/search | POST | search for users by username or status -/social/block | POST | block a user -/social/unblock | POST | unblock a user -/social/list/requests | GET | get a list of unaccepted friend requests -/social/list/blocks | GET | get a list of blocked people -/social/list/friends | GET | get a list of your friends -/game/new | POST | create a new private game -/game/random | POST | join or create a public game -/game/info | POST | -/game/accept | POST | accept game invite or rematch -/game/spectate | POST | spectate a game by id + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
endpointmethoddescriptionparametersauthorizationresponse
/statusGETget online user count and active game countnonenone + +```ts +{ + users: int, + games: int +} +``` +
/auth/loginPOSTlog in with email or username + +```ts +{ + email: string, + password: string +} +``` +noneempty response with the set_cookie header
/auth/signupPOSTsign up + +```ts +{ + username: string, + email: string, + password: string +} +``` +noneempty response with the set_cookie header
/user/infoGET|POSTget user info by username or id note: avatar is a uri to a 256x256 .png image + +```ts +{ + username?: string, + id?: userID +} +``` +none|user + +```ts +userInfo +``` +
/user/gamesGET|POSTget games of user + +```ts +{ id?: userID } +``` +none|user + +```ts +{ + games: Array, + totals: userGameTotals +} +``` +
/user/avatarGETfetch avatar as .png + +```ts +{ id?: userID } +``` +none|userPNG image
/user/avatarPOST +update avatar + +note: avatar is a client-resized 256x256 .png base64-encoded image, request +returns error when image is not .png or larger than 256x256 + + +```ts +{ image: base64PNG } +``` +usernone
/user/prefrencesGETfetch user preferencesnoneuser + +```ts +{ preferences: userPreferences } +``` +
/user/prefrencesPOSTchange user preferences + +```ts +{ newPreferences: userPreferences } +``` +usernone
/user/passwordPOSTupdate password + +```ts +{ + password: string, + newPassword: string, +} +``` +usernone
/user/emailPOSTupdate email + +```ts +{ + password: string, + email: string, +} +``` +usernone
/user/usernamePOSTupdate username + +```ts +{ + password: string, + username: string, +} +``` +usernone
/user/statusPOSTupdate status + +```ts +{ status: string } +``` +usernone
/user/searchFriendsPOSTsearch user's friend list
/social/requestPOSTsend a friend request to a user by user id
/social/acceptPOSTaccept a friend request
/social/removePOSTremove a friend from your friend list or delete a friend request from a user
/social/searchPOSTsearch for users by username or status
/social/blockPOSTblock a user
/social/unblockPOSTunblock a user
/social/list/requestsGETget a list of unaccepted friend requests
/social/list/blocksGETget a list of blocked people
/social/list/friendsGETget a list of your friends
/game/newPOSTcreate a new private game
/game/randomPOSTjoin or create a public game
/game/infoPOST
/game/acceptPOSTaccept game invite or rematch
/game/spectatePOSTspectate a game by id
## Events These are events that are fired by the socket.io connection -event|description|data|direction|context --|-|-|-|- -fieldUpdate|recieve new playfield from server|`{ field: string }`|`s -> c`|game -turnUpdate|recieve if it's player 1's move|`{ player1: boolean }`|`s -> c`|game -gameStart|sent when game starts|`none`|`s -> c`|game -finish|sent when game finishes|`none`|`s -> c`|game -resign|send to resign, is then forwarded to all subscribed clients|`none`|`s <-> c`|game -newMove|send a new move|`{ move: int, game_id: string }`|`s <- c`|game -registerGameListener|listen to events for a game|`{ id: string }`|`s <- c`|game -incomingFriendRequest|get notified of friend request|`none`|`s -> c`|global -changedRelation|get notified of a different relation to someone|`{ id: string }`|`s -> c`|global + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
eventdescriptiondatadirectioncontext
fieldUpdaterecieve new playfield from server{ field: string }s -> cgame
turnUpdaterecieve if it's player 1's move{ player1: boolean }s -> cgame
gameStartsent when game startsnones -> cgame
finishsent when game finishesnones -> cgame
resignsend to resign, is then forwarded to all subscribed clientsnones <-> cgame
newMovesend a new move{ move: int, game_id: string }s <- cgame
registerGameListenerlisten to events for a game{ id: string }s <- cgame
incomingFriendRequestget notified of friend requestnones -> cglobal
changedRelationget notified of a different relation to someone{ id: string }s -> cglobal
## How to test API endpoints ```sh -- cgit v1.2.3