Skip to content

Examples

Michael Pratt edited this page Jan 4, 2016 · 5 revisions

Examples

Below are some example usages of robusto framework.

Static URL w/ Spring Rest

This example shows a simple client that makes a POST call to a remote service using the ConstantUriProvider, which uses the same URI for every call (including retries). The client extends SpringRestClient and thus can easily call getRestTemplate() to get a fully initialized RestTemplate object to use for all of its remote calls. It uses a simple String for return types, but could easily be modified to use the Spring ResponseEntity type or even a custom DTO.

public class MyClient extends SpringRestClient
{
    public String createEntity(SomeDto body)
    {
        ApiCommand<String> command = restCommand(
            new ConstantUriProvider("https://api.google.com/v1/someservice"),
            new SpringInstanceCallback()
            {
                @Override
                public String runWithUrl(String url)
                {
                    return getRestTemplate().postForObject(
                        UriComponentsBuilder
                            .fromUriString(url)
                            .pathSegment("new").pathSegment("resource")
                            .build()
                            .toUriString(),
                        body,
                        String.class
                    );
                }
            }
        ).build();
    return command.execute();
    }
}
Clone this wiki locally