Demonstrate how to write clean express controllers using function currying, functionnal programming and promises.
- Promises helps avoiding callback hell
- Currying helps code reuse
- Functional programing makes data flow clearer
Yes, this sample shows obvious over-engineering. The provided API could be provided by simplier, clearer code. However, this code will scale on business complexity:
- handle more 'head' and 'tail' possible values: √
- asynchronously retrieve player data from playerName: √
- chain more actions: √
- add more game parameters won't change game signature: √
git clone https://gist.github.com/ce14ba85518e7809b0cd.git express_curry_promise
cd express_curry_promise
npm install
node app.js
... in another shell
curl -v http://localhost:3000/flip/head
curl -v http://localhost:3000/flip/tail
curl -v http://localhost:3000/flip/head
curl -v http://localhost:3000/flip/tail