View on GitHub

Restler

Generate clients for Web services automatically at run time, using their annotated Spring controller interfaces as input.

Download this project as a .zip file Download this project as a tar.gz file

/** 
*     An annotated Spring controller interface
*/
@Controller
@RequestMapping("greeter")
public interface Greeter {

    @RequestMapping("greetings/{language}") 
    String getGreeting(@PathVariable String language, 
                       @RequestParam(defaultValue = "Anonymous") String name); 

}

// Consuming code 
Service service = new Service("https://www.example.com/api");
Greeter greeter = service.getController(Greeter.class);
String greeting = greeter.getGreeting("en","Buddy"); 
// Result of https://www.example.com/api/greeter/greetings/en?name=Boddy call

// Session support in consuming code
Service service = new Service("https://www.example.com/api");
AuthorizationStrategy authorizationStrategy = new LoginAuthorizationStrategy(...);
Session session = service.startSession(authorizationStrategy);
Greeter greeter = service.getController(Greeter.class);
String greeting = greeter.getGreeting("en","Buddy");