New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for constant query string parameters #103

Closed
dcaunt opened this Issue Nov 26, 2012 · 19 comments

Comments

10 participants
@dcaunt

dcaunt commented Nov 26, 2012

At present the RestAdapter will simply append GET variables to an endpoint, beginning with a ?

It should be possible to detect the presence of existing query string variables and append Named parameters using ampersands.

Currently it's necessary to provide constant GET variables in every service call as a Named parameter.

// Doesn't quite work
public interface MyServiceAsync {

    // Produces a url like "endpoint?constantVariable=constantValue&page=1".
    @GET("endpoint?constantVariable=constantValue")
    void normalGet(@Named("page") int page,
                   Callback<MyResponse> callback);

}
@edenman

This comment has been minimized.

Contributor

edenman commented Nov 26, 2012

This should work just fine. Can you copy/paste what url is being generated from the above?

@JakeWharton

This comment has been minimized.

Collaborator

JakeWharton commented Nov 26, 2012

I think this is what @QueryParam is for.

@JakeWharton

This comment has been minimized.

Collaborator

JakeWharton commented Nov 26, 2012

It is.

Example:

@GET("endpoint")
@QueryParam(name="constantVariable", value="constantValue")
void normalGet(@Named("page") int page, Callback<MyResponse> callback);
@dcaunt

This comment has been minimized.

dcaunt commented Nov 27, 2012

Thanks guys, my bad. I should have looked at the tests.

Retrofit is fantastic but could use a little more documentation. I'm happy to contribute an amended readme if it's useful?

@pforhan

This comment has been minimized.

Contributor

pforhan commented Nov 27, 2012

Sure, put together a pull request and we'll be happy to review.

@JakeWharton

This comment has been minimized.

Collaborator

JakeWharton commented Nov 27, 2012

@dcaunt Retrofit will have a full website with documentation once it's useful enough to the general public. It's about 90% there but still has some awful APIs and assumptions before I'm comfortable telling anyone to use it. I'll try to whip up the beginnings of the site next week so that we can at least start getting a place for contributions to docs to go.

@dcaunt

This comment has been minimized.

dcaunt commented Nov 27, 2012

@JakeWharton Understood. I have a feeling this library is going to be wildly popular when you hit a 1.0 release.

@Macarse

This comment has been minimized.

Macarse commented Jun 22, 2013

QueryParam was removed in 2ef7ca0.

This removes support for @QueryParam/@QueryParams in favor of including constants in the declared URL itself.
e.g.,

@get("/list?foo=bar")

@roideuniverse

This comment has been minimized.

roideuniverse commented May 12, 2015

I have a situation where I need my params to be of contant value and I cannot declare it in the url itself. Removal of @QueryParams makes this not so good. 😞

@JakeWharton

This comment has been minimized.

Collaborator

JakeWharton commented May 12, 2015

Those statements are contradictory.

@roideuniverse

This comment has been minimized.

roideuniverse commented May 12, 2015

My bad, I just realized that weather I do in in the URL itself or in the @QueryParams, it makes no difference.

@snakemouse3d

This comment has been minimized.

snakemouse3d commented May 14, 2015

how can i make a request like this:
URL: "/rest/meterdetail/X"
X is a variable that i want to pass a value to.

  • answer: Oh, I forgot to use @path annotation.
@nizamsp

This comment has been minimized.

nizamsp commented Oct 15, 2016

I don't see this in Retrofit 2. What's the alternative for constant param and its value in Retrofit 2?

@tomblenz

This comment has been minimized.

tomblenz commented Oct 31, 2016

@nizamsp Encode into the url itself, eg.

@GET(".../CheckVersion/?os=android)

This still supports using variable @Query() params in conjunction.

@kevintanhongann

This comment has been minimized.

kevintanhongann commented Jan 23, 2017

The QueryParam annotation is super useful though. When you hardcode the query parameter into a url, it looks like it's gonna smell.

@tomblenz

This comment has been minimized.

tomblenz commented Jan 23, 2017

QueryParam is hardcoding. You should use Query if you need something variable.

@kevintanhongann

This comment has been minimized.

kevintanhongann commented Jan 24, 2017

@JakeWharton

This comment has been minimized.

Collaborator

JakeWharton commented Jan 24, 2017

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