A RESTful API with Chess logic made from scratch using TypeScript + Express.JS.
GET -- /api
-- Status route, can be used for measuring ping.
GET -- /api/games/new
-- Creates and returns a new game.
GET -- /api/games/:gameID
-- Returns the game info of the specified game ID.
GET -- /api/games/:gameID/moves/:pieceUID
-- Returns the valid moves (encoded) of the specified piece.
POST -- /api/games/:gameID/moves/:pieceUID
-- Moves the specified piece (pieceUID parameter in URL) to a specified position (moveTo property in JSON body)
GET
/api
(Returns the status of the API)
None
http code content-type response 200
application/json
{"status": "success", "timestamp": 1729072605904}
GET
/api/games/new
(Creates a new game and returns the game's information.)
None
http code content-type response 200
application/json
{"status": "success", "game": {...}
GET
/api/games/:gameID
(Returns the game information of the specified game ID.)
name type data type description gameID required number The unique ID of the game.
http code content-type response 200
application/json
{"status": "success", timestamp: 1729072605904, data: {...}, errors: []}
404
text/html
<html><body>NOT FOUND</body></html>
GET
/api/games/:gameID/moves/:pieceUID
(Returns valid moves of the specified piece.)
name type data type description gameID required number The unique ID of the game. pieceUID required number The unique ID of the piece.
http code content-type response 200
application/json
{"status": "success", "moves": [...] }
404
application/json
{"status": "failed", "message": "No piece exists for the specified UID." }
404
text/html
<html><body>NOT FOUND</body></html>
501
application/json
{"status": "failed", "message": "An error occured while generating moves." }
POST
/api/games/:gameID/moves/:pieceUID
(Moves the specified piece in the specified game to the specified position. (don't mind the alliteration)
none
property type required applies to information moveTo string yes All pieces
The position where the piece should move to.
killPos string no All pieces
The position of the piece that is to be captured; This value is different from "moveTo" property only in case of an en passant.
promoteTo string no Pawn
The piece that the pawn should be promoted to; Valid values are: "r, n, q, b" - Rook, Knight, Queen, and Bishop respectively.
castleTarget string no King
The position of the rook that is to be castled with.
http code content-type response 200
application/json
{"status": "success", game: {...}}
400
application/json
{"status": "failed", "message": "Invalid move." }
400
application/json
{"status": "failed", "message": "It is not your turn." }
404
text/html
<html><body>NOT FOUND</body></html>
404
application/json
{"status": "failed", "message": "No piece exists for the specified UID." }
501
application/json
{"status": "failed", "message": "An error occured while trying to move the specified piece." }
- Navigate to project's base directory from a terminal.
- Run
yarn install
ornpm install
. - Run
yarn start
ornpm start
.- The application will start listening for requests at port 3000.