Skip to content

Commit

Permalink
Examples for JS api in doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Kliment committed Mar 28, 2015
1 parent b1a1bbb commit 69a065d
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions docs/sandboxed-hooks.md
Expand Up @@ -20,11 +20,38 @@ Sandboxed hooks cen be used for running untrusted hook code. In each hook file y
- Memory limit is 1M
- Inside each hook you can access `stash` object variable which is passed between contexts of each hook function execution.
- Hook code is evaluated as `use strict`
- Sandboxed mode does not support CoffeScript hooks


## Examples

### Good
## CLI switch

```
$ dredd blueprint.md http://localhost:3000 --hokfiles path/to/hookfile.js --sandbox
```

## JS API

```javascript
Dredd = require('dredd');
configuration = {
server: "http://localhost",
options: {
path: "./test/fixtures/single-get.apib",
sandbox: true,
hookfiles: './test/fixtures/sandboxed-hook.js',
}
};
dredd = new Dredd(configuration);

dred.run(function(error, stats){
// your callback code here
});
```


### Stashing example
```javascript

after('First action', function(transaction){
Expand All @@ -40,7 +67,7 @@ before('Second action', funciton(transaction){
```


### Bad, throwing an exception
### Throwing an exception, hook function context is not shared
```javascript
var myObject = {};

Expand Down

0 comments on commit 69a065d

Please sign in to comment.