Package ratpack.retrofit
Class RatpackRetrofit
- java.lang.Object
-
- ratpack.retrofit.RatpackRetrofit
-
public abstract class RatpackRetrofit extends Object
Builder for providing integration of Retrofit2 with Ratpack'sHttpClient
.This class allows for creating declarative type-safe interfaces that represent remote HTTP APIs. Using this adapter allows for defining the interfaces to return
Promise
types which will be fulfilled by Ratpack's http client.import ratpack.exec.Promise; import ratpack.retrofit.RatpackRetrofit; import ratpack.test.embed.EmbeddedApp; import retrofit2.http.GET; import static org.junit.jupiter.api.Assertions.*; public class ExampleRetrofitClient { public interface HelloService { @GET("hello") Promise<String> hello(); } public static void main(String... args) throws Exception { EmbeddedApp api = EmbeddedApp.of(s -> s .handlers(chain -> chain .get("hello", ctx -> ctx.render("hello")) ) ); EmbeddedApp.of(s -> s .registryOf(r -> r .add(HelloService.class, RatpackRetrofit.client(api.getAddress()).build(HelloService.class) ) ) .handlers(chain -> { chain.get(ctx -> { ctx.render(ctx.get(HelloService.class).hello()); }); }) ).test(testHttpClient -> { assertEquals("hello", testHttpClient.getText()); api.close(); }); } }
- Since:
- 1.4
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
RatpackRetrofit.Builder
-
Constructor Summary
Constructors Constructor Description RatpackRetrofit()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static RatpackRetrofit.Builder
client(String endpoint)
Creates a new builder for creating Retrofit clients.static RatpackRetrofit.Builder
client(URI endpoint)
Creates a new builder for creating Retrofit clients.
-
-
-
Method Detail
-
client
public static RatpackRetrofit.Builder client(URI endpoint)
Creates a new builder for creating Retrofit clients.- Parameters:
endpoint
- the endpoint for client implementations.- Returns:
- a client builder
-
client
public static RatpackRetrofit.Builder client(String endpoint)
Creates a new builder for creating Retrofit clients.- Parameters:
endpoint
- the endpoint for client implementations. Converted toURI
.- Returns:
- a client builder
-
-