Browse Source

deps

master
Lloyd Brookes 8 years ago
parent
commit
05fa42ecbe
  1. 37
      example/built-in/mock/mocks/users2.js
  2. 16
      package.json

37
example/built-in/mock/mocks/users2.js

@ -0,0 +1,37 @@
const users = require('./users.json')
/* responses for /users */
const userResponses = [
{
route: '/users',
responses: [
/* Respond with 400 Bad Request for PUT and DELETE - inappropriate on a collection */
{ request: { method: 'PUT' }, response: { status: 400 } },
{ request: { method: 'DELETE' }, response: { status: 400 } },
{
/* for GET requests return a subset of data, optionally filtered on 'minAge' and 'nationality' */
request: { method: 'GET' },
response: function (ctx) {
ctx.body = users.filter(user => {
const meetsMinAge = (user.age || 1000) >= (Number(ctx.query.minAge) || 0)
const requiredNationality = user.nationality === (ctx.query.nationality || user.nationality)
return meetsMinAge && requiredNationality
})
}
},
{
/* for POST requests, create a new user and return the path to the new resource */
request: { method: 'POST' },
response: function (ctx) {
const newUser = ctx.request.body
users.push(newUser)
newUser.id = users.length
ctx.status = 201
ctx.response.set('Location', `/users/${newUser.id}`)
}
}
]
}
]
module.exports = userResponses

16
package.json

@ -33,18 +33,18 @@
"author": "Lloyd Brookes <75pound@gmail.com>",
"dependencies": {
"lws": "^1.0.0-pre.6",
"lws-blacklist": "^0.1.0",
"lws-body-parser": "^0.1.0",
"lws-compress": "^0.1.0",
"lws-conditional-get": "^0.1.0",
"lws-blacklist": "^0.2.0",
"lws-body-parser": "^0.2.0",
"lws-compress": "^0.2.0",
"lws-conditional-get": "^0.2.0",
"lws-cors": "^0.2.0",
"lws-index": "^0.2.0",
"lws-json": "^0.2.0",
"lws-log": "^0.2.1",
"lws-mime": "^0.1.0",
"lws-mock-response": "^0.1.0",
"lws-rewrite": "^0.2.1",
"lws-spa": "^0.1.2",
"lws-mime": "^0.2.0",
"lws-mock-response": "^0.2.0",
"lws-rewrite": "^0.2.2",
"lws-spa": "^0.2.0",
"lws-static": "^0.2.0"
},
"devDependencies": {

Loading…
Cancel
Save