# drakonian

> Generate an API server from [API Blueprint](https://apiblueprint.org/) documentation.

Latest version **2.3.2** (published 2016-10-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install drakonian
pnpm add drakonian
yarn add drakonian
bun add drakonian
```

Provides the command `drakonian`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.3.2 |
| Published | 2016-10-25 |
| First published | 2015-04-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Tiago Luchini |
| Maintainers | workco |

## Links

- npm: https://www.npmjs.com/package/drakonian
- Repository: https://github.com/workco/drakonian
- Homepage: https://github.com/workco/drakonian#readme
- Issues: https://github.com/workco/drakonian/issues
- npm.io page: https://npm.io/package/drakonian

## Dependencies (5)

- [nopt](https://npm.io/package/nopt.md) ^3.0.6
- [colors](https://npm.io/package/colors.md) ^1.1.2
- [lodash](https://npm.io/package/lodash.md) ^4.16.4
- [restify](https://npm.io/package/restify.md) ^4.1.1
- [protagonist](https://npm.io/package/protagonist.md) ^1.5.2

## Recent versions

- 2.3.2 (latest) — 2016-10-25
- 1.3.2 — 2016-02-05
- 1.3.1 — 2015-11-10
- 1.3.0 — 2015-11-10
- 1.2.0 — 2015-05-28
- 1.0.0 — 2015-04-16

## README

# drakonian

Generate an API server from [API Blueprint](https://apiblueprint.org/) documentation.

## Installing
```sh
npm install -g drakonian
```

## Running from console
 ```sh
$ drakonian blueprint.apib [[-p | --port] 8080] [-s | --silent] [-c | --customHandlers] handlers.js [-f | --formatters] formatters.js]]
```

## Running programatically

```js
var drakonian = require('drakonian');
drakonian.start('test/test_simple_resource.apib', 4000, done, { silent: true };
```
You can also configure custom headers to be allowed (due to CORS):

```js
drakonian.start('test/test_simple_resource.apib', 4000, done, { silent: true }, ['authorization']);
```

## Custom handlers

Add business logic to your API Blueprint by adding custom handlers.

```js
drakonian.addHandler('GET', '/things/{id}', function(req, res, accept, action) {
    var response = drakonian.findResponse(/200/, accept, action);
    drakonian.setHeaders(res, response.headers);
    if (req.headers.accept === 'application/json') {
        res.send({
            id: parseInt(req.params.id),
            name: 'Thing ' + req.params.id
        });
    } else {
        res.send('id: ' + req.params.id + ', name: "Thing ' + req.params.id + '"');
    }
});

drakonian.start('test/test_simple_resource.apib', 4000, done, { silent: true });
```

or

```js
var handlers = [
    {
        method: 'GET',
        uriTemplate: '/things/{id}',
        handler: function(req, res, accept, action) {
            // Handler code
        }
    }
];
    
drakonian.addHandlers(handlerObj.handlers);
```

## Public methods

* start = function(blueprintFile, port, cb, options)

* close = function()

* addHandler = function(verb, uriTemplate, cb)

## Other helper methods

 * setHeaders = function(res, headers)

 * findResponse = function(statusCode, accept, action)

 * yieldDefaultResponse = function(res, accept, action)

## Testing

```sh
npm test
```

---
_Source: https://npm.io/package/drakonian · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
