Skip to content

chess-centre/chess-players-api

Repository files navigation

The Chess Centre | API

GitHub Codacy

Chess Players API

A project for creating your own API player database.

Intro

This is a project for quickly creating a basic chess player API using the cool features of Lambda & DynamoDB from AWS, all written in TypeScript. It provides the initial CRUD operations exposed over HTTP.

You can use the chess-players npm package for downloading offically published player data. Together you can currate your own santized data source, for example only store top grandmasters!

Getting started

Prerequisites

Once you have created your account, proceed with the following:

npm i -g serverless

Running locally

Install dynamodb - to test your commands locally with postman or curl

sls dynamodb install

To understand more about working with DynamoDB offline see here: more info

sls offline start

Deploying

Before you deploy, ensure the serverless.yml is using the correct AWS region

provider:
  name: aws
  runtime: nodejs12.x
  region: eu-west-2 <---- change to your local region

Once your dependencies are all installed, run:

sls deploy

API

Name Method Lambda Description
/player POST createPlayer() creates a new Player record
/player/{id} GET getPlayer() returns a player record by id
/players GET getPlayers() returns all players (no limit)
/player/{id} PUT updatePlayer() updates a existing Player by id

Note: DELETE has been left out intentionally as this is an unlikely operation

More complex queries can be added and indexes on your database table will be useful depending on how you intend to use your data.

Player object

Basic properties for a player record.

interface Player {
  id: number,
  name: string,
  rating: number | null,
  country: string,
  createdAt: string,
}

Contributing

License: MIT