Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

@Get arbitrary parameters  #900

Description

@jkbbwr

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=true

There are a non trivial amount of parameters to this query, is there a declaration I can use to indicate this to the @rest interface?

Activity

  1. kclay commented on Jan 31, 2014

    @kclay

    Check this out https://gist.github.com/kclay/8744419, this is how I handle freeform searches

  2. jkbbwr commented on Feb 1, 2014

    @jkbbwr
    Author

    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 searches

    Reply to this email directly or view it on GitHubhttps://github.com//issues/900#issuecomment-33848340
    .

  3. DayS commented on Feb 3, 2014

    @DayS
    Contributor

    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 :)

  4. vincentjames501 commented on Mar 2, 2015

    @vincentjames501

    This would be super useful. I'm surprised more people haven't requested this for more complex querying. +1.

  5. WonderCsabo commented on Mar 2, 2015

    @WonderCsabo
    Member

    Unfortunately this is not a priority for us now, and our queue is very-very long. However, we always gladly accept pull requests.

  6. WonderCsabo commented on Jun 23, 2015

    @WonderCsabo
    Member

    BTW, we should also add @Query which could be added to the fields directly.

  7. WonderCsabo commented on Jun 23, 2015

    @WonderCsabo
    Member

    This could be easily done if we generate calls to the UriComponentsBuilder API.

  8. demonito commented on Jul 15, 2015

    @demonito

    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&param1=value2&param3=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.

  9. self-assigned this
    on Jul 15, 2015
  10. WonderCsabo commented on Jul 15, 2015

    @WonderCsabo
    Member

    @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!

  11. kihaki commented on Feb 22, 2017

    @kihaki

    Hey everyone, I was just wondering if there is any update on this?

  12. WonderCsabo commented on Feb 22, 2017

    @WonderCsabo
    Member

    Unfortunately we have limited to to work an AA, feel free to contribute!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions