The following example shows you how you can make a basic call against Cloudant using Cloudant Education's example database.
import org.springframework.web.client.RestTemplate;
public class Application {
private final static String URL =
"https://education.cloudant.com/animaldb/_design/views101/_view/latin_name?include_docs=true";
public static void main(String args[]) {
RestTemplate restTemplate = new RestTemplate();
// Normally you would bind the response to Java domain objects and not String
// See https://spring.io/guides/gs/consuming-rest/ for examples of binding
// response objects to Java domain objects
String animals = restTemplate.getForObject(URL, String.class);
System.out.println(animals);
}
}
You should see some output similar to this:
...
{
"total_rows": 5,
"offset": 0,
"rows": [
{
"id": "kookaburra",
"key": "Dacelo novaeguineae",
"value": 19,
"doc": {
"_id": "kookaburra",
"_rev": "4-6038cf35dfe1211f85484dec951142c7",
"min_length": 0.28,
"max_length": 0.42,
"wiki_page": "http:\/\/en.wikipedia.org\/wiki\/Kookaburra",
"class": "bird",
"diet": "carnivore",
"latin_name": "Dacelo novaeguineae"
}
},
...
]
}
...
NOTE: