3

I have a search format the client side, that needs to be translated at the server controller to:

Item.find(search)
.limit(limit).skip(skip)
.exec(function(err, items) 
     {return return res.jsonp(items);  });

where:

search = {"tiltle" : new RegExp(<some_token>, "i"), 
          "price" : {"$lt" : <price_limit>},
           "labels" : {"$in" : <labels_list>} }
limit = <limit_pagination>
skip = <skip_pagination>

All <x> variables should come from the client.

Which API can I define for the above search query?

Option 1

Have all variables as a url query parameters:

GET /items?skip=100&limit=50&pricelt=50&labels=ONE,TWO&title=titl

But adding each field to the url seems not a generic solution (both the client controller and the server controller will have to specify these fields).

Option 2

Create a separate POST query for search:

POST /items/search?skip=100&limit=50
{"title" : new RegExp("titl", "i"), 
          "price" : {"$lt" : 50},
           "labels" : {"$in" : ["ONE","TWO"]} }

That seems to break the simplicity of the RESTful apis. (Can't override POST /items cause it's reserved for creating items.

Option 3

GET request with body:

GET /items?skip=100&limit=50
{"title" : new RegExp("titl", "i"), 
          "price" : {"$lt" : 50},
           "labels" : {"$in" : ["ONE","TWO"]} }

But this seems to break the HTTP 1.1 protocol

Community
  • 1
  • 1
skme
  • 721
  • 5
  • 19

0 Answers0