Could we create same GET URI but with different query parameters?
For Example: I have two REST GET URIs:
/questions/ask/?type=rest
/questions/ask/?byUser=john
Now the REST service is not recognizing two GET methods as separate and considering it only 1 GET method which is declared as first.
- why is it behaving this way?
- Is there any way that I could make two GET methods having different Query Parameters?
It would be highly appreciated if you could quote any resource.
You can not have two getters with same uri but different request parameters. What you can do is to have one getter method with many request parameters.
then call it with two parameters
You have to handle the logic inside test method to handle these parameters accordingly.
Regarding Darijan, I think that it is up to to decide to go with two methods or one method considering what the underline logic is. If you are going with 2 methods then use two uri. If the business logic is ok to go with one uri then use the way I answered
You cannot
Overload
REST
requests.In your business layer you would have to check which of the two variables are set and then you will have to do the required processing.
You can overload the rest endpoint in termsof what request/query parameters are present in the request. Here's the answer that solved my use case: create two method for same url pattern with different arguments
Because a resource is uniquely identified by its PATH (and not by its params). Two resources you define have the same PATH.
According to JSR-311 spec:
Since your data model includes two distinct resources I suggest making two rest methods with different paths:
This is the RESTful way, since one URI represents one and only one resource and there should be no overloading. If one URI represents more than one resource that means you got it wrong somewhere.