Repository navigation
@Get arbitrary parameters #900
Description
Activity
Check this out https://gist.github.com/kclay/8744419, this is how I handle freeform searches
I thought AA was all about removing boiler plate :(
On Fri, Jan 31, 2014 at 10:19 PM, Keyston notifications@github.com wrote:
Check this out https://gist.github.com/kclay/8744419, this is how I
handle freeform searchesReply to this email directly or view it on GitHubhttps://github.com//issues/900#issuecomment-33848340
.Just to be sure, you're trying to dynamically inject query params in your URL ?
If so, this feature is not available yet, but it could be something like :
@GET("http://api.lmiforall.org.uk/api/v1/ashe/estimateHours") List<User> groupList(@QueryMap Map<String, String> params);
This is a good idea. Feel free to contribute :)
Reacted by Tobias PreussThis would be super useful. I'm surprised more people haven't requested this for more complex querying. +1.
Unfortunately this is not a priority for us now, and our queue is very-very long. However, we always gladly accept pull requests.
BTW, we should also add
@Querywhich could be added to the fields directly.This could be easily done if we generate calls to the
UriComponentsBuilderAPI.When I needed to create @get request with many dynamic parameteres, and some of them could be duplicated, I had resolved that problem so:
@Rest(rootUrl = "http://example.com:9080/", converters = { GsonHttpMessageConverter.class }, interceptors = { ApiInterceptor.class }) public interface ExampleApi { @Get("content/home/product-type/list?{filters}&domain={domain}") //filters is String like "param1=value1¶m1=value2¶m3=value3" ProductTypeListResponse getProductTypeList(int domain, String filters); } public class ApiInterceptor implements ClientHttpRequestInterceptor { private static final String TAG = ApiInterceptor.class.getSimpleName(); @Override public ClientHttpResponse intercept(final HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException { final QueryMultiParamsHttpRequest modifiedRequest = new QueryMultiParamsHttpRequest(request); return execution.execute(modifiedRequest, body); } } public class QueryMultiParamsHttpRequest implements HttpRequest { private static final String TAG = QueryParametersBuilder.class.getSimpleName(); private HttpRequest httpRequest; public QueryMultiParamsHttpRequest(final HttpRequest httpRequest) { this.httpRequest = httpRequest; } @Override public HttpMethod getMethod() { return httpRequest.getMethod(); } @Override public URI getURI() { final URI originalURI = httpRequest.getURI(); final String query = originalURI.getQuery() != null ? originalURI.getQuery().replace("%3D", "=").replace("%26", "&") : null; URI newURI = null; try { newURI = new URI(originalURI.getScheme(), originalURI.getUserInfo(), originalURI.getHost(), originalURI.getPort(), originalURI.getPath(), query, originalURI.getFragment()); } catch (URISyntaxException e) { Log.e(TAG, "Error while creating URI of QueryMultiParamsHttpRequest", e); } return newURI; } @Override public HttpHeaders getHeaders() { return httpRequest.getHeaders(); } }
So, I created a wrapper for HttpRequest, that can decode symbols "=" and "&". And this wrapper replace original HttpRequest in ApiInterceptor. This is some hacky solution, but it works.
@demonito thanks for sharing your solution, it will help others as well. I am sorry that you have to use a hack. I have this feature in my queue, but that is very long unfortunetly. I am planning to include this in AA 4.0, though. Stay tuned!
Hey everyone, I was just wondering if there is any update on this?
Unfortunately we have limited to to work an AA, feel free to contribute!
It seems that I am unable to set arbitrary query parameters to a @get declaration
My endpoint looks like
http://api.lmiforall.org.uk/api/v1/ashe/estimateHours?soc=2349&coarse=trueThere are a non trivial amount of parameters to this query, is there a declaration I can use to indicate this to the @rest interface?