take-home coding challenge; REST API
Please note requires Node 8 and higher due to ES6 syntax w/o babel!
1. git clone https://github.com/larswww/rock-paper-cygsors.git && cd rock-paper-cygsors
2. npm install
3. npm run start
(make sure the app isn't already running)
- npm run test (intergration and unit)
OR
- npm run unit (unit only)
- npm run e2e (intergration only)
curl -H "Content-Type: application/json" -d '{"name":"Lars", "move":"rock"}' http://localhost:3000/api/games
(Don't forget to replace the id with id return from first call in subsequent two calls)
curl -X PUT -H "Content-Type: application/json" -d '{"name":"Pete", "move":"paper"}' http://localhost:3000/api/games/ee38d234-1c42-4771-96bc-b65f699aa2ad/move
curl http://localhost:3000/api/games/ee38d234-1c42-4771-96bc-b65f699aa2ad
In short I simplified the original requirements into 3 calls. Endpoints will return REST compliant status codes and headers.
POST /api/games
- payload: {name: 'Lars', move: 'rock'} (required)
PUT /api/games/{id}/move
- payload: {name: 'Steve', move: 'rock'} (required)
GET /api/games/{id}
- Web framework: Fastify and Fastify-rate-limit plugin
- UUID (v4)
- In-memory store: Keyv
- Implemented Rock Paper Scissors as my own separate npm module Sten-Sax-Pase
- Test framework: Mocha
- Chai for assertions
- Chai-Http plugin for simple intergration tests
- Javascript Standard Style for linting
Resource based structure
├── src
│ ├── resources
│ │ └── games
│ │ ├── model.js
│ │ ├── api.js
│ │ ├── dao.js
│ │ ├── router.js
│ │ └── schema.js
│ └── server.js
│ └── index.js
└── test
└── games
├── intergration.test.js
└── unit.test.js