Backend Development 19 min read

Retrofit Spring Boot Starter: Lightweight HTTP Client Integration with Advanced Features

This article introduces the Retrofit Spring Boot Starter, a lightweight HTTP client framework for Spring Boot that simplifies HTTP request handling, supports custom OkHttpClient injection, annotation‑based interceptors, logging, retry, error decoding, circuit‑breaker integration, connection‑pool management, global interceptors, microservice calls, and flexible call adapters and converters.

Architect's Tech Stack
Architect's Tech Stack
Architect's Tech Stack
Retrofit Spring Boot Starter: Lightweight HTTP Client Integration with Advanced Features

The Retrofit Spring Boot Starter provides a seamless way to integrate Retrofit, a type‑safe HTTP client, into Spring Boot applications, offering a lightweight solution for making HTTP requests without the boilerplate of RestTemplate or HttpClient.

Key features include custom OkHttpClient injection, annotation‑based interceptors (including URL‑based and custom annotations), configurable logging levels and strategies, automatic request retry with customizable rules, error decoding into exceptions, and optional circuit‑breaker support powered by Sentinel.

Configuration is handled via application.yml or application.properties , allowing you to enable logging, define connection pools, set retry policies, specify global interceptors, and configure circuit‑breaker parameters such as enable-degrade and degrade-type .

Usage examples demonstrate defining HTTP interfaces with @RetrofitClient , adding @GET , @POST , and @Body annotations, and injecting the generated client into Spring services. Advanced topics cover custom interceptors for adding timestamps or signatures, global interceptors for adding headers, and microservice calls using @RetrofitClient(serviceId=..., path=...) with a ServiceInstanceChooser .

The starter also supports flexible call adapters (e.g., Call<T> , CompletableFuture<T> , Response<T> , and plain Java objects) via BodyCallAdapterFactory and ResponseCallAdapterFactory , and data converters such as Jackson, Gson, Moshi, and others, configurable globally or per‑interface.

<code>retrofit:
  enable-log: true
  logging-interceptor: com.github.lianjiatech.retrofit.spring.boot.interceptor.DefaultLoggingInterceptor
  retry-interceptor: com.github.lianjiatech.retrofit.spring.boot.retry.DefaultRetryInterceptor
  global-converter-factories:
    - retrofit2.converter.jackson.JacksonConverterFactory
  global-call-adapter-factories:
    - com.github.lianjiatech.retrofit.spring.boot.core.BodyCallAdapterFactory
    - com.github.lianjiatech.retrofit.spring.boot.core.ResponseCallAdapterFactory
  enable-degrade: true
  degrade-type: sentinel
  resource-name-parser: com.github.lianjiatech.retrofit.spring.boot.degrade.DefaultResourceNameParser</code>

Overall, the Retrofit Spring Boot Starter offers a powerful, extensible, and production‑ready HTTP client solution for Spring Boot developers.

JavaMicroservicesLoggingcircuitbreakerHTTPSpringBootRetrofit
Architect's Tech Stack
Written by

Architect's Tech Stack

Java backend, microservices, distributed systems, containerized programming, and more.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.