Retrofit: Rate Limiting Specific API

Created on 16 Feb 2015  路  4Comments  路  Source: square/retrofit

Has there ever been any talk of rate limiting specific api's? Or from a dev's perspective should this be left up to the end user to tackle? Just curious as I'm needing it for a requirement.

For example, an api that takes in search terms, and returns a list of matching results. I intended to send each character as a new request to the api, but rate limiting for even 2 full seconds would be appropriate, to not hit the API to often.

Most helpful comment

You can do this yourself using RxJava. It's definitely an application-level concern, not Retrofit. Retrofit just maps HTTP semantics onto Java interfaces.

Observable<String> text = ...
text.throttleLast(2, SECONDS)
    .flatMap(retrofitApiCall())
    .subscribe(result -> System.out.println("result: " + result));

where retrofitApiCall() is some interface method that returns Observable<Result>.

All 4 comments

You can do this yourself using RxJava. It's definitely an application-level concern, not Retrofit. Retrofit just maps HTTP semantics onto Java interfaces.

Observable<String> text = ...
text.throttleLast(2, SECONDS)
    .flatMap(retrofitApiCall())
    .subscribe(result -> System.out.println("result: " + result));

where retrofitApiCall() is some interface method that returns Observable<Result>.

Awesome thanks for the quick reply @JakeWharton !

any way of doing that without using rx?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kkunsue picture kkunsue  路  3Comments

vkislicins picture vkislicins  路  3Comments

starktonys picture starktonys  路  3Comments

attaullahpro picture attaullahpro  路  3Comments

ramonmoraes8080 picture ramonmoraes8080  路  3Comments