GitHunt
TO

tomasbjerre/spring-rest-client

Dynamically create Spring Rest (proxy class) client from annotated interface.

Spring Rest Client

Maven Central

Dynamically create Spring (proxy class) client from annotated interface. Very lightweight, only depends on spring-web:4.3, compared to alternatives like Feign.

Given MyApiInterface is a Spring-annotated Java interface.

final MyApiInterface myClient = SpringRestClientBuilder
  .create(MyApiInterface.class)
  .setUrl(this.getMockUrl())
  .setRestTemplate(restTemplate)         // Optional
  .setHeader("header-name", "the value") // Optional
  .setHeaders(HttpHeaders)               // Optional
  .build();

Here myClient is a dynamically created Java Proxy object.

final ResponseEntity<MyDTO> response = myClient.getMyDto();

The method invocation (getMyDto()) on that object (myClient) will be translated to a HTTP request using the annotations of that method in that interface. And response will be the result of that HTTP request.

Supports both RequestMapping, like @RequestMapping(value = "/doget/{theId}", method = RequestMethod.GET), and composed format, like @GetMapping("/doget/{theId}").

Supports both signatures:

  • ResponseEntity<X> deleteOrder(Long)
  • X deleteOrder(Long)

See also test cases.

Languages

Java100.0%

Contributors

Latest Release

1.5.0January 22, 2025
Apache License 2.0
Created November 5, 2021
Updated October 6, 2025