Skip to content

Ribbon Annotations

allenxwang edited this page Sep 12, 2014 · 2 revisions

Getting Started

You can access network resources (currently HTTP resource is supported) by defining interfaces with Ribbon annotations, and get an instance of the interface from Ribbon and invoke the methods like a normal Java object where network access happens behind the scene. Here is an simple example to start with:

public interface MovieService {
    @Http(  method = HttpMethod.GET,
            uri = "http://localhost:8080/users/{userId}/recommendations")
    RibbonRequest<ByteBuf> recommendationsByUserId(@Var("userId") String userId);
}

The interface definition tells Ribbon to make a GET request to the URI and replace {userId} with actual value of userId passed into the method call.

The application can create an instance of MovieService and invoke its method:

    movieService = Ribbon.from(MovieService.class);
    Observable<ByteBuf> result = movieService.recommendationsByUserId(TEST_USER).toObservable();