fiapi
aims to make managing the internal structure of APIs as easy as possible.
$ ls lib/
method_a.js method_b.js method_c.js
var fiapi = require('fiapi');
fiapi({ root: 'lib/' }, function (err, api) {
console.log(api);
// { method_a: [Function], method_b: [Function], method_c: [Function] }
});
$ npm install fiapi
Firstly require
fiapi and then use as follows:
Arguments
opts
-Object
containing configuration for thefiapi
call:opts.root
- (string, default:__dirname
of wherefiapi
is being called) Root directory of the API.opts.recursive
(boolean, default:false
) - Whether or not to recurse directories withinopts.root
opts.pattern
(regex, default:/.*/
) - Pattern of files to include in the API.
callback(err, api)
- A callbackfunction
which is called when calls to all files in applicable directory have been aggregated into anapi
object or an error occurs.
Note that only files which export
a function
will be included in your API 😄
Examples
Given the project structure:
|- bin
|- cli.js
|- lib
|- my_namespace
|- method_d.js
|- method_e.js
|- api.js
|- method_a.js
|- method_b.js
|- method_c.js
package.json
// lib/api.js
fiapi(function (err, api) {
// { method_a: [Function], method_b: [Function], method_c: [Function] }
});
// bin/cli.js
fiapi({ root: '../lib', pattern: /^method/ }, function (err, api) {
// { method_a: [Function], method_b: [Function], method_c: [Function] }
});
// bin/cli.js
fiapi({ root: '../lib', pattern: /^method/, recursive: true }, function (err, api) {
// {
// method_a: [Function],
// method_b: [Function],
// method_c: [Function],
// my_namespace: {
// method_d: [Function],
// method_e: [Function]
// }
// }
}