Resteeth dynamically creates rest clients based on plain java interface with Spring MVC annotations. Ready to use beans are available through standard Spring injections.
- 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'
- 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 {
}
- 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);
}
- 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);