retrofit2.http.Query Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of retrofit Show documentation
Show all versions of retrofit Show documentation
A type-safe HTTP client for Android and Java.
/*
* Copyright (C) 2013 Square, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package retrofit2.http;
import java.lang.annotation.Annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import java.lang.reflect.Type;
import retrofit2.Retrofit;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
* Query parameter appended to the URL.
*
* Values are converted to strings using {@link Retrofit#stringConverter(Type, Annotation[])}
* (or {@link Object#toString()}, if no matching string converter is installed)
* and then URL encoded.
* {@code null} values are ignored. Passing a {@link java.util.List List} or array will result in a
* query parameter for each non-{@code null} item.
*
* Simple Example:
*
* @GET("/friends")
* Call<ResponseBody> friends(@Query("page") int page);
*
* Calling with {@code foo.friends(1)} yields {@code /friends?page=1}.
*
* Example with {@code null}:
*
* @GET("/friends")
* Call<ResponseBody> friends(@Query("group") String group);
*
* Calling with {@code foo.friends(null)} yields {@code /friends}.
*
* Array/Varargs Example:
*
* @GET("/friends")
* Call<ResponseBody> friends(@Query("group") String... groups);
*
* Calling with {@code foo.friends("coworker", "bowling")} yields
* {@code /friends?group=coworker&group=bowling}.
*
* Parameter names and values are URL encoded by default. Specify {@link #encoded() encoded=true}
* to change this behavior.
*
* @GET("/friends")
* Call<ResponseBody> friends(@Query(value="group", encoded=true) String group);
*
* Calling with {@code foo.friends("foo+bar"))} yields {@code /friends?group=foo+bar}.
*
* @see QueryMap
* @see QueryName
*/
@Documented
@Target(PARAMETER)
@Retention(RUNTIME)
public @interface Query {
/** The query parameter name. */
String value();
/**
* Specifies whether the parameter {@linkplain #value() name} and value are already URL encoded.
*/
boolean encoded() default false;
}