periodicjs.core.responder
Description
Core responder is a component of periodicjs.core.controller that provides adapters for different formatting responses across different content types. Each adapter may have options specific to the content type, but after being constructed the same methods are exposed. Depending on content type adapters do everything from wrapping JSON data in a standard way to rendering HTML from templates.
Full Documentation
Usage (basic)
const AdapterInterface = ;var adapter = AdapterInterface;//Basic usage (JSON)//With no callback param returns a Promiseadapter ;//With a callback paramadapter;//Second param can also be configurable options sync: true will handle operation synchronouslylet result = adapter;/* { "result": "success", "status": 200, "data": { "foo": "bar" } }*///Formatting can also be customizedlet result = adapter;/* { "custom": "field", "data": { "foo": "bar" } }*///Basic usage (XML)adapter = AdapterInterface;adapter ;//configuration for XML rendering can also be passedadapter;//Basic usage (HTML)//Since template rendering is inherently async the sync option is ignoredadapter = AdapterInterface;//By default HTML adapter renders EJS templatesadapter ;//Custom template engines can also be used as long as they expose a .render methodadapter = AdapterInterface;adapter ;
Usage (HTML Adapter Advanced)
const AdapterInterface = ;const mustache = ;const path = ;//Because the adapter uses the .render method of the template engine you can overwite this .render method to further customize behaviorvar render = mustacherender;mustache { mustache; return ;};const adapter = AdapterInteraface;//You can customize which directories .render will search for the template by passing .dirname. This also optimizes .render because custom directories are searched ahead of the theme/extension directoriesadapter ;
Usage (with custom adapter)
const AdapterInterface = ;const template = { return `Hello !`;};const CustomAdapter = class { ... } { return ; } { return `There was an error: :(`; };var adapter = AdapterInterface;adapter; //Hello Jim!
Development
Make sure you have grunt installed
$ npm install -g grunt-cli jsdoc-to-markdown
For generating documentation
$ grunt doc$ jsdoc2md adapters/**/*.js index.js > doc/api.md
Notes
- Check out https://github.com/typesettin/periodicjs for the full Periodic Documentation
Testing
$ npm i$ grunt test
Contributing
License
MIT