/rock-paper-cygsors

take-home coding challenge; REST API

Primary LanguageJavaScriptMIT LicenseMIT

rock-paper-cygsors

take-home coding challenge; REST API

Usage

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

Tests

(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)

Run in Postman

Curl Commands

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

Endpoints

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}

Direct dependencies

Dev dependencies

Structure

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