I want to perform request using Retrofit2 and RxJava
public static Observable<Post> getPostsAround(Location location, int offset, int limit) {
if(api==null) {
new RestService(); //initialize API in constructor
}
return api.getPostsAround(location.getLatitude(),location.getLongitude(),offset,limit)
.flatMapIterable(posts -> posts); //transform Observable<List<Post>> to Observable<Post> which emits posts onNext
}
I tried @Headers("Authorization: code) annotation, but I don't know how to change "code" in runtime.
I have found an answer: A request Header can be updated dynamically using the @Header annotation. A corresponding parameter must be provided to the @Header. If the value is null, the header will be omitted. Otherwise, toString will be called on the value, and the result used.
@GET("user")
Call<User> getUser(@Header("Authorization") String authorization)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With