-
Notifications
You must be signed in to change notification settings - Fork 1
Parameters
Marlon Carvalho edited this page Jul 20, 2015
·
3 revisions
Assume that a request has been made to this URI http://yourdomain.com/beers/1/comments?author=name&tags=ipa
. How's it possible to access all path and query parameters in this URI? Lets see it in action.
@API(path: 'beers')
class BeerAPI {
@GET(path: ':id/comments')
String get(Parameters pathParams, Parameters queryParams) {
return "PathParam: ${pathParams.getInt('id')} - QueryParams: ${queryParams.getString('author')}-${queryParams.getString('tags')}";
}
}
You need to add two parameters to your API method, one named pathParams
and another named queryParams
. These two methods can be either an instance of Map
or Parameter
. However, if you don't have conflicting parameters, you can turn it even easier:
@API(path: 'beers')
class BeerAPI {
@GET(path: ':id/comments')
String get(Map params) {
return "PathParam: ${params['id']} - QueryParams: ${params['author']}-${params['tags']}";
}
}
Darter merges the parameters coming from the path and query into one single Map
instance. Nevertheless, take into account that if there're parameters with the same name in both places, the path parameters take precedence and will replace any query parameter using the same name.