Updated readme with useful example

This commit is contained in:
Dan Hough
2014-03-14 22:44:26 +01:00
parent 9b214f135c
commit 7f835fe88d
2 changed files with 29 additions and 2 deletions

3
.gitignore vendored
View File

@@ -12,4 +12,5 @@ logs
results
node_modules
npm-debug.log
npm-debug.log
.DS_Store

View File

@@ -54,7 +54,33 @@ Run `interfake -?` for a full list of command-line options.
-----
Interfake allows for more complex API structures, post-response endpoints and two different methods of mocking up new endpoints: by loading the file as above, or on-the-fly using an HTTP meta-API.
Interfake allows for more complex API structures, post-response endpoints and three different methods of mocking up new endpoints: the JavaScript API (useful for tests), by loading a file (like above), or on-the-fly using an HTTP meta-API.
## Method 3: JavaScript
Make sure you've install Interfake as a local module using `npm install interfake --save`. Then, you can start doing things like this:
```javascript
var interfake = require('interfake');
var request = require('request'); // Let's use request for this example
interfake.createRoute({
request: {
url: '/endpoint',
method: 'get'
},
response: {
code: 200,
body: {}
}
});
interfake.listen(3030); // The server listens on port 3030
request('http://localhost:3030/endpoint', function (error, response, body) {
console.log(response.statusCode); // prints 200
});
```
## Method 1: JSON File