My previous attempt with PHP.
-
Decoupling decisions from effects
Solution: The world is impure. Instead, we strive towards implementing as much of our code base as pure functions, so that an application is impure only at its boundaries. Using functional composition with monads, we can succinctly conditionally compose from pure and impure functions.
Benefits: Pure functions only makes a decision based on input, and returns information about this decision as output, so is easy to unit test. Impure functions are used as humble functions that you may don't need to unit test. Impure functions can call pure functions, so at the boundary, an application must gather impure data, and use it to call pure functions. This automatically leads to the ports and adapters architecture.
From Dependency injection to dependency rejection video by Mark Seemann
From dependency injection to dependency rejection text by Mark Seemann
Test-Driven Development with F# course by Mark Seemann
Dependency Rejection and TDD without Mocks video by Антон Молдован
- Express (HTTP)
- Awilix (IoC)
- Fluture (Asynchronous monadic structure)
- Folktale (Result, ADT)
- Ajv (JSON Schema validator)
- Bristol (Logger)
- MongoDB (DB, optional)
To run this application, you will need:
- Node.js 9.0+
- npm or something similar
npm install
npm run start
npm run test
See .env
file.
APP_CAPACITY = 10
APP_DATABASE = 'memory'
NODE_ENV = 'production'
HTTP_HOST = 'localhost'
HTTP_PORT = 80
MONGODB_URL = 'mongodb://localhost:27017/booking?connectTimeoutMS=300'
JSONSCHEMA_ASYNC_VALIDATE = true
curl -X POST http://localhost/reservations/ \
-H 'Content-Type: application/json' \
-d '{"date": "Y-m-d H:i:s", "name": "Some name", "email": "Some email", "quantity": 1}'