json-server
Advanced tools
Comparing version 0.7.26 to 0.7.27
@@ -0,5 +1,21 @@ | ||
# Change Log | ||
## [0.7.27][2015-09-02] | ||
### Added | ||
```bash | ||
# Support OR | ||
GET /posts?id=1&id2 | ||
GET /posts?category=javascript&category=html | ||
``` | ||
## [0.7.26][2015-09-01] | ||
### Added | ||
- `GET /posts?embed=comments` | ||
- `GET /posts?expand=user` | ||
```bash | ||
# Support embed and expand in lists | ||
GET /posts?embed=comments | ||
GET /posts?expand=user | ||
``` |
{ | ||
"name": "json-server", | ||
"version": "0.7.26", | ||
"version": "0.7.27", | ||
"description": "Serves JSON files through REST routes.", | ||
@@ -5,0 +5,0 @@ "main": "./src/server/index.js", |
@@ -77,6 +77,7 @@ # JSON Server [![](https://travis-ci.org/typicode/json-server.svg)](https://travis-ci.org/typicode/json-server) [![](https://badge.fury.io/js/json-server.svg)](http://badge.fury.io/js/json-server) [![](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/typicode/json-server?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) | ||
GET /posts?title=json-server&author=typicode | ||
GET /posts?id=1&id=2 | ||
GET /comments?author.name=typicode | ||
``` | ||
To slice resources, add `_start` and `_end` or `_limit` (an `X-Total-Count` header is included in the response). | ||
To slice resources, add `_start` and `_end` or `_limit` (an `X-Total-Count` header is included in the response) | ||
@@ -96,3 +97,3 @@ ``` | ||
To make a full-text search on resources, add `q`. | ||
To make a full-text search on resources, add `q` | ||
@@ -103,3 +104,3 @@ ``` | ||
To embed resources, add `_embed`. | ||
To include children resources, add `_embed` | ||
@@ -111,3 +112,3 @@ ``` | ||
To expand inner resources, add `_expand`. | ||
To include parent resource, add `_expand`. | ||
@@ -119,3 +120,3 @@ ``` | ||
Returns database. | ||
Returns database | ||
@@ -126,3 +127,3 @@ ``` | ||
Returns default index file or serves `./public` directory. | ||
Returns default index file or serves `./public` directory | ||
@@ -129,0 +130,0 @@ ``` |
@@ -44,5 +44,2 @@ var express = require('express') | ||
// Filters list | ||
var filters = {} | ||
// Resource chain | ||
@@ -86,19 +83,20 @@ var chain = db(name).chain() | ||
// Add query parameters filters | ||
// Convert query parameters to their native counterparts | ||
for (var key in req.query) { | ||
// don't take into account JSONP query parameters | ||
Object.keys(req.query).forEach(function (key) { | ||
// Don't take into account JSONP query parameters | ||
// jQuery adds a '_' query parameter too | ||
if (key !== 'callback' && key !== '_') { | ||
filters[key] = utils.toNative(req.query[key]) | ||
} | ||
} | ||
// Always use an array, in case req.query is an array | ||
var arr = [].concat(req.query[key]) | ||
// Filter | ||
if (!_(filters).isEmpty()) { | ||
for (var f in filters) { | ||
// This syntax allow for deep filtering using lodash (i.e. a.b.c[0]) | ||
chain = chain.filter(f, filters[f]) | ||
chain = chain.filter(function (element) { | ||
return arr | ||
.map(utils.toNative) | ||
.map(function (value) { | ||
return _.matchesProperty(key, value)(element) | ||
}).reduce(function (a, b) { | ||
return a || b | ||
}) | ||
}) | ||
} | ||
} | ||
}) | ||
@@ -105,0 +103,0 @@ // Sort |
@@ -9,4 +9,6 @@ var os = require('os') | ||
request = request('http://localhost:3000') | ||
var PORT = 3100 | ||
request = request('http://localhost:' + PORT) | ||
var tmpDir = path.join(__dirname, '../../tmp') | ||
@@ -18,3 +20,3 @@ var dbFile = path.join(tmpDir, 'db.json') | ||
var bin = path.join(__dirname, '../..', pkg.bin) | ||
return cp.spawn('node', [bin].concat(args), { | ||
return cp.spawn('node', [bin, '-p', PORT].concat(args), { | ||
stdio: 'inherit', | ||
@@ -21,0 +23,0 @@ cwd: __dirname |
@@ -98,2 +98,10 @@ var assert = require('assert') | ||
it('should support multiple filters', function (done) { | ||
request(server) | ||
.get('/comments?id=1&id=2') | ||
.expect('Content-Type', /json/) | ||
.expect([db.comments[0], db.comments[1]]) | ||
.expect(200, done) | ||
}) | ||
it('should support deep filter', function (done) { | ||
@@ -106,2 +114,10 @@ request(server) | ||
}) | ||
it('should ignore JSONP query parameters callback and _ ', function (done) { | ||
request(server) | ||
.get('/comments?callback=1&_=1') | ||
.expect('Content-Type', /text/) | ||
.expect(new RegExp(db.comments[0].body)) // JSONP returns text | ||
.expect(200, done) | ||
}) | ||
}) | ||
@@ -108,0 +124,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
53938
1401
278