1

Example: We have below operation:

GET /employees 

I have to have functionality to allow filtering using multiple names as parameter. I represent it something like below:

GET /employees?empNames=xxx,yyy,zzz

But, now I don't have a parameter called empName, instead I have two parameters empFirstName and empSurname.

Which will be like below:

GET /employees?empFirstName=xx&empSurname=x

But I still need the API to accept multiple names(empFirstName and empSurname) filter.

I can see a few ways to represent it as below:

GET /employees?name=(xx,x),(yy,y),(zz,z)
GET /employees?name=xx:x,yy:y,zz:z
GET /employees?name=[{empFirstName=xx, empSurname=yy},{empFirstName=yy, empSurname=zz},{empFirstName=aa, empSurname=bb}]

What could be the best restful representation for such a filtering.

Are there any standards on which separator you need to use in the URI, a : or a , or something else? What's the simplest and best way to do this?

nitgeek
  • 1,250
  • 12
  • 20
  • Possible duplicate of [REST API Best practice: How to accept list of parameter values as input](https://stackoverflow.com/questions/2602043/rest-api-best-practice-how-to-accept-list-of-parameter-values-as-input) – ctor Jul 27 '17 at 04:00
  • No it's not a duplicate. That question is talKing only about single 1D array. My question is different. – nitgeek Jul 27 '17 at 04:30

1 Answers1

0

Well, it seems that your need is quite specific and sending a standard GET request with a bunch of parameters is not good enough. There is no reason to limit oneself to this method. I would consider a POST request which may be useful in searching (thanks to accepting a data in a more friendly way).

Then I would prepare a request body

POST /employees/search

{
    "conditions": [
         {
             "empFirstName": "xx",
             "empSurname": "yy"
         },
         {
             "empFirstName": "yy",
             "empSurname": "zz"
         },
         ...
    ]
}

or even more explicitly, according to some existing rules of creating a logic queries, mongo notation for example:

{
    "$or": [
        {
            "empFirstName": "xx",
            "empSurname": "yy"
        },
        {
             "empFirstName": "yy",
             "empSurname": "zz"
        },
        ...       
    ]
}
Piotr Dawidiuk
  • 2,961
  • 1
  • 24
  • 33