Question
· Jul 27, 2017

REST: How to pass query parameters

Hello.

I'm having difficulties trying to figure (if possible) how to  create an URL that also matches query parameters.

I tried:

 <Route Url="/:namespace/test(\?id\=):id" Method="GET" Call="Test"/>
 <Route Url="/:namespace/test?(id)=:id" Method="GET" Call="Test"/>
 <Route Url="/:namespace/test?id=:id" Method="GET" Call="Test"/>

But none of these worked.

Is it possible when using %CSP.REST or am I restricted to using route parameters?

Thank you.

EDIT:
 

Forget about the "id" parameter name. It's a bad sample: normally id are by definition, able to be hierarchically included in the URI.

Think on id as being something that's not hierarchical, like the sample below:


/users/1?fields=list,of,fields,i,want,to,show

This would force the URI to be designed in a way that can't be expressed by route paramers, since "fields" doesn't belong to users, as it's really abstract.

So let's consider the URLMap as:

<Route Url="/users/:id(\?fields\=):fields" Method="GET" Call="Test"/>
 <Route Url="/users/:id?(fields)=:fields" Method="GET" Call="Test"/>
 <Route Url="/users/:id?fields=:fields" Method="GET" Call="Test"/>

Discussion (5)0
Log in or sign up to continue

I think that the default convention for REST usage has been exploited too much already, to the point that most would prefer to have an extra feature than follow it strictly. Even Google and Facebook do it: though they use REST most of their services, they also allow to pass query parameters.

I think it's due to their performance or readability policies.

EDIT:

By allowing query parameters, you can also prevent another rule break: 

Let's say I need to pass a lot of parameters to FETCH data from a resource. As REST demand, you need to use GET verb to fetch data from the resource if you won't change it.

However if you can't use query parameters, you need to use POST or PUT to provide the payload (that modifies data) and this would break the CRUD rule as well.

This is where I would balance the rule breaks, that is, I can't really disregard breaking a rule that actually prevents me from breaking another that's even more explicit.