Skip to content

Repository files navigation

Chess-API

A RESTful API with Chess logic made from scratch using TypeScript + Express.JS.

Summarized list of API Endpoints:

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)

Description of API Endpoints

Status route

GET/api(Returns the status of the API)
Parameters

None

Response(s)
http codecontent-typeresponse
200application/json{"status": "success", "timestamp": 1729072605904}

Create a new chess game:

GET/api/games/new(Creates a new game and returns the game's information.)
Parameters

None

Response(s)
http codecontent-typeresponse
200application/json{"status": "success", "game": {...}

Get a game's information by ID:

GET/api/games/:gameID(Returns the game information of the specified game ID.)
Parameters
nametypedata typedescription
gameIDrequirednumberThe unique ID of the game.
Response(s)
http codecontent-typeresponse
200application/json{"status": "success", timestamp: 1729072605904, data: {...}, errors: []}
404text/html<html><body>NOT FOUND</body></html>

Get moves of a piece:

GET/api/games/:gameID/moves/:pieceUID(Returns valid moves of the specified piece.)
Parameters
nametypedata typedescription
gameIDrequirednumberThe unique ID of the game.
pieceUIDrequirednumberThe unique ID of the piece.
Response(s)
http codecontent-typeresponse
200application/json{"status": "success", "moves": [...] }
404application/json{"status": "failed", "message": "No piece exists for the specified UID." }
404text/html<html><body>NOT FOUND</body></html>
501application/json{"status": "failed", "message": "An error occured while generating moves." }

Moving a piece:

POST/api/games/:gameID/moves/:pieceUID(Moves the specified piece in the specified game to the specified position. (don't mind the alliteration)
Parameters

none

Body (JSON) properties
propertytyperequiredapplies toinformation
moveTostringyesAll piecesThe position where the piece should move to.
killPosstringnoAll piecesThe position of the piece that is to be captured; This value is different from "moveTo" property only in case of an en passant.
promoteTostringnoPawnThe piece that the pawn should be promoted to; Valid values are: "r, n, q, b" - Rook, Knight, Queen, and Bishop respectively.
castleTargetstringnoKingThe position of the rook that is to be castled with.
Response(s)
http codecontent-typeresponse
200application/json{"status": "success", game: {...}}
400application/json{"status": "failed", "message": "Invalid move." }
400application/json{"status": "failed", "message": "It is not your turn." }
404text/html<html><body>NOT FOUND</body></html>
404application/json{"status": "failed", "message": "No piece exists for the specified UID." }
501application/json{"status": "failed", "message": "An error occured while trying to move the specified piece." }

Setup:

  1. Navigate to project's base directory from a terminal.
  2. Run yarn install or npm install.
  3. Run yarn start or npm start.
    • The application will start listening for requests at port 3000.

About

A RESTful Chess API made using Node.JS.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages