Skip to content

Commit aa0d2e3

Browse files
committed
Rollback to _start and _end query params and update README.md
1 parent 053484d commit aa0d2e3

File tree

3 files changed

+29
-16
lines changed

3 files changed

+29
-16
lines changed

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,19 @@ PATCH /:resource/:id
128128
DEL /:resource/:id
129129
```
130130

131-
To slice resources, add `_start` and `_end` to query parameters.
131+
To slice resources, add `_start` and `_end`.
132+
133+
```
134+
GET /:resource?_start=&end=
135+
GET /:resource?filter=&filter=&_start=&end=
136+
GET /:parent/:parentId/:resource?_start=&end=
137+
```
138+
139+
To make a full-text search on resources, add `q`.
140+
141+
```
142+
GET /:resource?q=
143+
```
132144

133145
For routes usage information, have a look at [JSONPlaceholder](https://github.com/typicode/jsonplaceholder) code examples.
134146

src/routes.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ routes.db = function(req, res, next) {
1313
// GET /:resource?q=
1414
// GET /:resource?attr=&attr=
1515
// GET /:parent/:parentId/:resource?attr=&attr=
16-
// GET /*?*&limit=
17-
// GET /*?*&offset=&limit=
16+
// GET /*?*&_end=
17+
// GET /*?*&_start=&_end=
1818
routes.list = function(req, res, next) {
1919

2020
// Filters list
@@ -23,16 +23,17 @@ routes.list = function(req, res, next) {
2323
// Result array
2424
var array
2525

26-
// Remove offset and limit from req.query to avoid filtering using those
26+
// Remove _start and _end from req.query to avoid filtering using those
2727
// parameters
28-
var offset = req.query.offset
29-
var limit = req.query.limit
28+
var _start = req.query._start
29+
var _end = req.query._end
3030

31-
delete req.query.offset
32-
delete req.query.limit
31+
delete req.query._start
32+
delete req.query._end
3333

3434
if (req.query.q) {
3535

36+
// Full-text search
3637
var q = req.query.q.toLowerCase()
3738

3839
array = low(req.params.resource).where(function(obj) {
@@ -67,14 +68,14 @@ routes.list = function(req, res, next) {
6768
}
6869
}
6970

70-
// Slicing result
71-
if (limit) {
71+
// Slice result
72+
if (_end) {
7273
res.setHeader('X-Total-Count', array.length)
7374
res.setHeader('Access-Control-Expose-Headers', 'X-Total-Count')
7475

75-
offset = offset || 0
76+
_start = _start || 0
7677

77-
array = array.slice(offset, limit)
78+
array = array.slice(_start, _end)
7879
}
7980

8081
res.jsonp(array)

test/server.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ describe('Server', function() {
7979
})
8080
})
8181

82-
describe('GET /:resource?limit=', function() {
82+
describe('GET /:resource?_end=', function() {
8383
it('should respond with a sliced array', function(done) {
8484
request(server)
85-
.get('/comments?limit=2')
85+
.get('/comments?_end=2')
8686
.expect('Content-Type', /json/)
8787
.expect('x-total-count', low.db.comments.length.toString())
8888
.expect('Access-Control-Expose-Headers', 'X-Total-Count')
@@ -91,10 +91,10 @@ describe('Server', function() {
9191
})
9292
})
9393

94-
describe('GET /:resource?offset=&limit=', function() {
94+
describe('GET /:resource?_start=&_end=', function() {
9595
it('should respond with a sliced array', function(done) {
9696
request(server)
97-
.get('/comments?offset=1&limit=2')
97+
.get('/comments?_start=1&_end=2')
9898
.expect('Content-Type', /json/)
9999
.expect('x-total-count', low.db.comments.length.toString())
100100
.expect('Access-Control-Expose-Headers', 'X-Total-Count')

0 commit comments

Comments
 (0)