Skip to content

API query parameters #358

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
alexsuslov opened this issue Jul 16, 2014 · 1 comment
Open

API query parameters #358

alexsuslov opened this issue Jul 16, 2014 · 1 comment

Comments

@alexsuslov
Copy link

To control api we are use:

Comparison Query Operators

EQ

  • url: /api/item?name=test
    • name: 'test'
  • url: /api/item?name.second=test
    • "name.second": 'test'

NEQ

  • url: /api/item?name=!test
    • name: $ne: 'test'

GT

  • url: /api/item?name=>1
    • name: $gt: 1

GTE

  • url: /api/item?name=]1
    • name: $gte: 1

LT

  • url: /api/item?name=<1
    • name: $lt: 1

LTE

  • url: /api/item?name=[1
    • name: $lte: 1

IN

  • url: /api/item?name=@1|2|3
    • name: $in: ['1','2','3']

NIN

  • url: /api/item?name=#1|2|3
    • name: $nin: ['1','2','3']

Evaluation Query Operators

REGEX

  • url: /api/item?name=~test
    • name: $regex: 'test'

Sort

  • /api/item?order=name
  • /api/item?order=-name

Limit

  • /api/item?limit=25&skip=0

We make simple module to convert resp.query to "mongose model find"

https://github.com/alexsuslov/wcQuery

Simple use in server api controller:

"use strict"

_ = require("lodash")
Item = require("./item.model")
Query = require("wc-query")
fields = {}

# Get list of items
exports.index = (req, res) ->
  query = Query(req.query)
  Item.find query.conditions, fields, query.options, (err, items) ->
    throw err if err
    return handleError(res, err)  if err
    res.json 200, items

BRGD
Alex

@DaftMonk
Copy link
Member

Thanks for sharing, I'll definitely use this.

@JaKXz JaKXz added the info label Jul 27, 2014
@Awk34 Awk34 changed the title to make api more power API query parameters Jul 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants