XIBLEDOCS

Routes files allow a developer to host REST API routes on the XIBLE API endpoint.

Since XIBLE exposes an express.js router, their docs are applicable here.

routes/flow.js

Explanation

URL

Internally, every node saved in a flow gets its own _id parameter. This _id is key to where the node API router is hosted;

/api/nodes/${NODE.name}/routes/flow/${NODE._id}/

Example

This example would expose the following routes;

  • GET /api/nodes/${NODE.name}/routes/flow/${NODE._id}/hello
  • PUT /api/nodes/${NODE.name}/routes/flow/${NODE._id}/data
'use strict';// export a function to run when XIBLE startsmodule.exports = (NODE, ROUTER, SERVE_STATIC) => {  // setup a simple GET route  ROUTER.get('/hello', (req, res) => {    res.json({ hello: 'world' });  });  // handle some input  ROUTER.put('/data', (req, res) => {    // store the data in the vault    // this will now be available in the node    // through NODE.getData('data', state)    NODE.vault.set({ data: req.body.data });    res.end();  });};

routes/global.js

Explanation

URL

/api/nodes/${NODE.name}/routes/global/

Example

This example would expose the following routes;

  • GET /api/nodes/${NODE.name}/routes/global/hello
  • PUT /api/nodes/${NODE.name}/routes/global/data
'use strict';// export a function to run when XIBLE startsmodule.exports = (ROUTER, SERVE_STATIC) => {  // setup a simple GET route  ROUTER.get('/hello', (req, res) => {    res.json({ hello: 'world' });  });  // handle some input  ROUTER.put('/data', (req, res) => {    // store the data in the vault    // this will now be available in the node    // through NODE.getData('data', state)    NODE.vault.set({ data: req.body.data });    res.end();  });};

Implementation examples