Skip to content

tomasbjerre/spring-rest-client

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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 signatures:

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

See also test cases.

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages