Skip to content

Conversation

MuhammadReda
Copy link

Set index route to be filtered, sorted and paged via query strings.

Example:

  • Return only fields name and info.
  • Sort results by name in ascending order.
  • Return only 3 results, starting from page 1

would be translated to: /api/things?fields=name,info&sort=name&direction=asc&limit=3&page=1

@Awk34
Copy link
Member

Awk34 commented Feb 23, 2015

I have something very similar in my own local copy. First, I like to use defaults instead of reverting to null for certain things, and also to use maximums, like this:

var DEFAULT_QUERY_LIMIT = 10;
var MAX_QUERY_LIMIT = 25;
var queryLimit = req.query.limit ? _.min([req.query.limit, MAX_QUERY_LIMIT]) : DEFAULT_QUERY_LIMIT;

Also, I can't suggest using skip(x). It works fine for small collections, but once they get large it starts to degrade in performance, since it iterates over each item that it skips.

@Awk34
Copy link
Member

Awk34 commented May 11, 2016

Closed due to inactivity

@Awk34 Awk34 closed this May 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants