A simple Javascript wrapper to easily interface with Mountebank and not have to deal with its
abstract object structure requirements. See SwaggerBank for easy intergration with Swagger Specs/YAML files
While not providing an API for the full feature list that mountebank has, MountebankHelper provides enough functionality so that it reflects the core purpose of Mountebank and is easy to use at the same time.
In the future this library will probably become a full-fledged Javascript wrapper around several of Mountebanks powerful CLI commands
// import the mountebank helper library
const mbHelper = require('mountebank-helper');
// create the skeleton for the imposter (does not post to MB)
const firstImposter = new mbHelper.Imposter({ 'imposterPort' : 3000 });
// construct sample responses and conditions on which to send it
const sample_response = {
'uri' : '/hello',
'verb' : 'GET',
'res' : {
'statusCode': 200,
'responseHeaders' : { 'Content-Type' : 'application/json' },
'responseBody' : JSON.stringify({ 'hello' : 'world' })
}
};
const another_response = {
'uri' : '/pets/123',
'verb' : 'PUT',
'res' : {
'statusCode': 200,
'responseHeaders' : { 'Content-Type' : 'application/json' },
'responseBody' : JSON.stringify({ 'somePetAttribute' : 'somePetValue' })
}
};
// add our responses to our imposter
firstImposter.addRoute(sample_response);
firstImposter.addRoute(another_response);
// start the MB server and post our Imposter to listen!
mbHelper.startMbServer(2525)
.then(function() {
firstImposter.postToMountebank()
.then( () => {
console.log('Imposter Posted! Go to https://localhost:3000/hello');
});
});
Now you can navigate to localhost:3000/hello to see the mocked response!
The port on which the main Mountebank server is to listen on This will start up the main Mountebank server and have it start listening for imposter create/update requests. This must be called before making any postToMountebank or updateResponse calls Constructor for the Imposter class which serves as the main entry point for interacting with Mountebank.A single instance of an Imposter class represents a single Mountebank imposter listening on a single port.
The port on which the Imposter is to listen on for incoming traffic The protocol the Imposter is to run on Adds a new stub to the imposter. A stub represents a combination of a predicate (conditions to be met) and a response (the response to be returned when those conditions are met).
This library only provides functionality for the equals predicate meaning, only complete response matches can be used as a predicate. See usage at end of README
{
"uri" : some_uri, // URI against which we are matching an incoming request
"verb" : GET, // HTTP method against which we are matching an incoming request
"res" : // The response that is to be returned when the above conditions get met
{
"statusCode" : 200,
"responseHeaders" : {"Content-Type" : "application/json"},
"responseBody" : JSON.stringify({"hello" : "world"})
}
}
- Support for fuzzy matching (via regex) on incoming-request body content (as opposed to exact path match) [DONE]
- Include the process of starting the Mountebank server as part of existing Functionality (abstract it away from the client so they don't have to call startMbServer() )
- Travis CI Build Setup [DONE]
- Post to NPM as installable module [DONE]
- Increase Code Coverage to 95%