Skip to content

A Spring Boot Starter for creating REST clients using Retrofit

Notifications You must be signed in to change notification settings

marknazareno/retrofit-spring-boot

Repository files navigation

Spring Boot Starter for Retrofit

based on https://github.com/spring-cloud-incubator/spring-cloud-square

Retrofit turns your HTTP API into a Java interface.

This starter provides auto configuration for creating REST clients using Retrofit. Just create your interfaces and annotate them as RetrofitClient.

Usage

Add dependency

<dependency>
    <groupId>com.mnazareno</groupId>
    <artifactId>retrofit-spring-boot-starter</artifactId>
    <version>1.0-SNAPSHOT</version>
</dependency>

Create your interface

@RetrofitClient(name = "github", baseUrl = "https://api.github.com")
public interface GithubApi {
    @GET("/repos/{owner}/{repo}/contributors")
    Call<List<Contributor>> contributors(@Path("owner") String owner, @Path("repo") String repo);
}

You can specify a configuration specific to a client if needed.

@RetrofitClient(name = "fooApi", baseUrl = "https://api.foo.com", configuration = { FooConfiguration.class } )
public interface FooApi {
    @GET("/users")
    Call<List<User>> getUsers();
}

public class FooConfiguration {
    @Bean
    public OkHttpClient httpClient() {
    	Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxy.company.com", 8080));
    	return new OkHttpClient.Builder().proxy(proxy).build();
    }
}

Ready to Use

Please refer to retrofit-spring-boot-starter-demo for sample usage

Response<List<Contributor>> response = githubApi.contributors("square", "retrofit").execute();
System.out.println(response);

About

A Spring Boot Starter for creating REST clients using Retrofit

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages