What are bindings?
This project and documentation are work in progress
Example code: src/bindings
Bindings take a library that has been instantiated with adapters, and expose it to the outside world. In the case of the example project, our binding is a REST HTTP interface, but you could write a binding to support GraphQL, pub/sub events, or even commands from a user interface (like in a CLI app).
Example: the Express binding
To make the community library app into a webservice, I've written an Express.js binding that maps library functions to incoming HTTP calls:
The Route
function is defined in src/bindings/express.route.ts and takes an object with four fields:
the fn from the library to call
a function that validates the input into the format expected
a function to extract input from Express'
Request
objecta function for handling success and responding with the right status code
The example route function also manages validation failure and how to log and respond to exceptions.
The route function isn't provided as a cast iron code example, rather a suggestion for how you can reduce boilerplate in your Express apps. Use it just as a starting point and make your own customisations.
Last updated