In the challenge, it is specified :
The Apex class must be called 'AnimalLocator', have a 'getAnimalNameById' method that accepts an Integer and returns a String.
and i cannot understand the line :
public class AnimalLocator {
public static String getAnimalNameById(Integer id){
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://th-apex-http-callout.herokuapp.com/animals/'+ id);
request.setMethod('GET');
HttpResponse response = http.send(request);
if (response.getStatusCode() == 200) {
Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
System.debug(results);
if(results.size() > 0){
for (Object animal : results.values()) {
System.debug(animal);
}
}
}
return String.valueOf(response) ;
}
}
As the debug result, i get ->
DEBUG|{"animals": ["majestic badger", "fluffy bunny", "scary bear", "chicken", "mighty moose"]}
The expected result must be ->
{"animal":{"id":1,"name":"chicken","eats":"chicken food","says":"cluck cluck"}}
i am unable to understand the issue!
id
variable must benull
.id
value you are requesting.id
is not null