npm install --save rest-emulator
var express = require('express');
var restEmulator = require('restEmulator');
var config = {
'/api/users': {
data: [
{name: 'Name1'},
{name: 'Name2'}
]
}
};
var app = express();
app.use(restEmulator(config));
app.listen(3000);
mocks/
default.js
users/
default.js
custom.js
cities/
default.js
custom.js
country.js
module.exports = {
'/api/users': {
data: [
{ name: 'John' },
{ name: 'Adam' }
]
},
'/api/cities': {
data: [
{ name: 'New York' },
{ name: 'Miami' }
],
query: {
'name=Miami': {
data: [
{ name: 'Miami' }
]
},
'name=New York': {
data: [
{ name: 'New York' }
]
}
}
code: 200,
timeout: 5000
}
};
module.exports = {
'/api/users': {
GET: {
data: [
{ name: 'John' },
{ name: 'Adam' }
],
query: {
'name=John': {
data: [
{ name: 'John' }
]
}
}
},
POST: {
data: {
success: true
},
code: 201,
timeout: 1000
}
}
};
module.exports = {
'/api/users': {
GET: {
default: {
data: [
{ name: 'John' },
{ name: 'Adam' }
],
code: 200,
timeout: 0
},
blank: {
data: [],
code: 200,
timeout: 0
},
increase: {
data: [
{ name: 'John' },
{ name: 'Adam' },
{ name: 'Clark' },
{ name: 'Earl' }
],
code: 200,
timeout: 0
}
},
POST: {
default: {
data: {
success: true
},
code: 201
},
error: {
code: 405
}
}
},
'/api/cities': {
'GET': {
data: [
{ name: 'New York' },
{ name: 'Miami' }
],
query: {
'name=Miami': {
data: [
{ name: 'Miami' }
]
},
'name=New York': {
data: [
{ name: 'New York' }
]
}
}
}
}
};