Skip to content

YoYo178/Chess-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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 code content-type response
200 application/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 code content-type response
200 application/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
name type data type description
gameID required number The unique ID of the game.
Response(s)
http code content-type response
200 application/json {"status": "success", timestamp: 1729072605904, data: {...}, errors: []}
404 text/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
name type data type description
gameID required number The unique ID of the game.
pieceUID required number The unique ID of the piece.
Response(s)
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." }

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
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.
Response(s)
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." }

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.