test-rest
v1.1.2
Published
A lightweight server for testing REST backends
Downloads
8
Readme
test-rest
A lightweight and simple to user REST API testing server. You can even unleash it as a development backend to get rid of those annoying mock backends.
Built upon the excellent Hapi framework.
Installation
Simply install the latest version via npm npm install test-rest
.
To install the latest development version you can install it directly from git via npm
npm install git+ssh://[email protected]:ptMuta/test-rest.git#master
(See npm docs for more information)
Configuration
The only required configuration for the server is the specification file for the server endpoints.
Usage
You can either import the test-server module with require('test-rest')
or install the module globally and use the
command line interface to run the server using test-server [-c HAPI_CONFIG] server_config
You can also check the cli help -h
and version -v
Example Configuration
The following configuration implements all the features currently available. If you don't need the custom handler functions you can pass in a plain json object as well.
export default {
"identifierKey": "id",
"routes": [
{
"path": "projects",
"methods": [
"GET_ALL",
"GET_BY_KEY",
"POST",
"PUT",
"DELETE"
],
"state": [
{"id": 1, "name": "MasterProject1"}
],
"nested": [
{
"path": "tasks",
"methods": [
"GET_ALL",
"GET_BY_KEY",
"POST",
"PUT",
"DELETE",
(path, state) => {
return {
path: `${path}/meta`,
method: 'GET',
handler: (request, reply) => reply({type: 'metaResponse', state})
}
}
],
"state": [
{"id": 1, "name": "MasterProject2"}
]
}
]
}
]
};
Documentation
See GitHub Pages.