Skip to content

An example REST API for managing game scores using AWS DynamoDB

Notifications You must be signed in to change notification settings

bhbdev/game-score-api

Repository files navigation

Game Score API

An simple example RESTful API built with:

  • Node.js
  • Express
  • AWS DynamoDB

Prerequisites

  • Node.js (v18 or higher)
  • Docker and Docker Compose
  • AWS CLI (for local DynamoDB management)
  • pnpm (package manager)

Project Setup

  1. Clone the repository
git clone https://github.com/bhbdev/game-score-api
cd game-score-api
  1. Install dependencies
pnpm install
  1. Environment Setup

Copy the example environment file:

cp .env.example .env

The .env file contains:

  • PORT: API server port (default: 4000)
  • AWS_ACCESS_KEY_ID: AWS access key (fake credentials for local development)
  • AWS_SECRET_ACCESS_KEY: AWS secret key (fake credentials for local development)
  • AWS_REGION: AWS region (default: us-east-1)
  • DYNAMODB_ENDPOINT: Local DynamoDB endpoint (default: http://localhost:8000)

Database Setup

  1. Start the local DynamoDB container
docker-compose up -d
  1. Create the required tables
make db-tables

This creates a GameScores table with the required schema.

Running the Application

Development Mode

pnpm dev

This starts the application with nodemon, which will automatically restart when files change.

Production Mode

pnpm build
pnpm start

API Endpoints

The application exposes the following endpoints for game score management:

  • GET /scores - Fetch all the game scores
  • GET /scores/:id - Fetch game score by ID
  • POST /scores - Create/update game scores
  • DELETE /scores/:id - Delete a game score by ID

Project Structure

├── docker/           # Docker configuration files
├── public/           # Static assets 
├── src/              # Source code
│   ├── controllers/  # Request handlers
│   ├── models/       # Data models
│   ├── routes/       # API route definitions
│   ├── app.ts        # Express app setup
│   └── index.ts      # Application entry point
├── .env.example      # Example environment variables
├── docker-compose.yml # Docker services configuration
├── Makefile          # Utility commands
├── package.json      # Project metadata and dependencies
└── tsconfig.json     # TypeScript configuration

Database Management

To reset or clear the database:

make db-drop

Notes (config)

  • The Docker Compose file defines and exposes the DynamoDB container port
  • The .env file defines the DYNAMODB_ENDPOINT which points to the DynamoDB container on the same port

License

MIT

About

An example REST API for managing game scores using AWS DynamoDB

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published