RESTfool is largely just a set of higher order functions that produce middleware for mocking responses with assertions and fixture data. These middleware also report request and response information to a RESTfool Dashboard instance for debugging and analysis of each made call.
Getting Started
Install via npm:
npm install restfool
Create a server.js
file and require restfool:
var restfool =
Starting a server
RESTfool requires an Express server to serve mocked routes and the dashboard. You can choose to add the middleware yourself, but it's recommended to have RESTfool create and configure a server for you.
var server = restfool server server
Fixture Data
RESTfool makes it easy to generate fake fixture data by using the fixture()
method. The fixture()
methods accepts either an object literal containing, or a function that returns, the desired output schema. When using the object literal method, you can pass in functions to generate values dynamically.
Note: We're using the faker library below to quickly generate fake data.
var faker = // object literalvar postFixture = restfool // functionvar userFixture = restfool
Generating rows
Now that you've defined the schema for the data, you can output a single row by calling the makeOne()
method or a defined number of rows using the make()
method.
var one = postFixture// => { title: 'Lorem ipsum dolor', ... } var many = postFixture// => [ {...}, {...}, {...} ]
You can override the results of custom values by passing an object or function in as a second argument.
var active = userFixture// => [ {name: '...', active: true}, {name: '...', active: true} ] var noNicks = userFixture
Generating middleware
You can also generate middleware quickly using the send()
and sendOne()
methods. These methods function the same as their "make" counterparts but will send a 200 JSON response containing the data.
server
Mocking entire resources
You know what's even cooler than sending completely dynamic fixture data? Mocking data persistence complete with scaffolded routes!
Note: RESTfool simply stores the data in memory. This means that the data will be lost once the server is closed.
var uuid = var posts = restfool
The following events are supported: create, update, save, delete