Skip to content

Codearte/resteeth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

76 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Resteeth

Resteeth dynamically creates rest clients based on plain java interface with Spring MVC annotations. Ready to use beans are available through standard Spring injections.

Build Status Coverage Status Maven Central Apache 2

Usage

  1. Add dependencies

In Maven projects (pom.xml):

<pom>
    ...
    <dependencies>
        <dependency>
            <groupId>eu.codearte.resteeth</groupId>
            <artifactId>resteeth</artifactId>
            <version>0.2.0</version>
        </dependency>
    </dependencies>
    ...
</pom>

In Gradle projects (build.gradle):

repositories {
   mavenCentral()
}
...
testCompile 'eu.codearte.resteeth:resteeth:0.2.0'
  1. Enable configuration

In SpringBoot projects Resteeth will work out of the box without any configuration needed. For classical projects you have to annotate your configuration with @EnableResteeth

@Configuration
@EnableResteeth
public class FooSpringConfig {

}
  1. Prepare interface
interface FooRestInterface {

	@RequestMapping(value = "/foos/{id}", method = RequestMethod.GET)
	Foo getFoo(@PathVariable("id") Integer id);

	@RequestMapping(value = "/foos", method = RequestMethod.POST)
	void postFoo(@RequestBody Foo user);

}
  1. Use!

with single URL

@RestClient(endpoints = {"http://api.mydomain.com"})
private FooRestInterface fooRestInterface;

Foo foo = fooRestInterface.getFoo(123);

or with round robin load balancing

@RestClient(endpoints = {"http://api1.mydomain.com/", "http://api2.mydomain.com/"})
private FooRestInterface fooRestInterface;

Foo foo = fooRestInterface.getFoo(123);