apeman-api
Remote api call
Installation
Install apeman-api module via npm.
$ npm install apeman-api -g
Usage
- Prepare an Apemanfile.js at your project root.
- Run the command via CLI.
Apemanfile.js
/** Example of Apemanfile.js */ 'use strict' const co = moduleexports = $cwd: __dirname $pkg: /* ... */ $proto: /* ... */ $api: // Define APIs 'sign': { return } { /* ... */ }
Then, start the server with command
$ apeman-api
Client Script
#!/usr/bin/env 'use strict' const apemanApiClient = const co =
CLI Options
$ apeman-api -h Usage: apeman-api [options] Remote api call Options: -h, --help output usage information -V, --version output the version number -p, --port <port> Port number -c, --configuration <configuration> Pathname of Apemanfile Examples: $ apeman-api -p 3000 # Start apeman api server
Programmatic API
apeman-api also provide programmatic API.
Firstly, install the module locally.
$ npm install apeman-api --save-dev
Then,
#!/usr/bin/env 'use strict' const apemanApi = const co =
Programmatic Options
Key | Description | Default |
---|---|---|
port | Port number | |
configuration | Pathname of Apemanfile |
Advanced Usage
This is a more advance example of apeman api.
Names starts with $
and @
has special meaning and not treated as api module.
Apemanfile.js
/** Example of Apemanfile.js */ 'use strict' const co = moduleexports = $cwd: __dirname $pkg: /* ... */ $proto: /* ... */ get const sign = const session = const debug = 'my-project:api' const db = this$ctx return // Define APIs 'sign': // Called before method invocation const s = this let module method params = sstateinvocation // Called after method invocation let s = this let module method returns = sstateinvocation // Koa middlewares $middlewares: // You can define custom scope with `@` prefix '@admin': user: { /* ... */ }
License
This software is released under the MIT License.