An simple example RESTful API built with:
- Node.js
- Express
- AWS DynamoDB
- Node.js (v18 or higher)
- Docker and Docker Compose
- AWS CLI (for local DynamoDB management)
- pnpm (package manager)
- Clone the repository
git clone https://github.com/bhbdev/game-score-api
cd game-score-api
- Install dependencies
pnpm install
- 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)
- Start the local DynamoDB container
docker-compose up -d
- Create the required tables
make db-tables
This creates a GameScores
table with the required schema.
pnpm dev
This starts the application with nodemon, which will automatically restart when files change.
pnpm build
pnpm start
The application exposes the following endpoints for game score management:
GET /scores
- Fetch all the game scoresGET /scores/:id
- Fetch game score by IDPOST /scores
- Create/update game scoresDELETE /scores/:id
- Delete a game score by ID
├── 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
To reset or clear the database:
make db-drop
- The Docker Compose file defines and exposes the DynamoDB container port
- The
.env
file defines theDYNAMODB_ENDPOINT
which points to the DynamoDB container on the same port
MIT