User Story
As a user, I want to add a new animal to a remote server by making an HTTP POST request using the PostAnimal method in the herokuapp class.
Code
public class herokuapp {
public static void PostAnimal(){
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://th-apex-http-callout.herokuapp.com/animals');
request.setMethod('POST');
request.setHeader('Content-Type', 'application/json;charset=UTF-8');
request.setBody('{"name":"Tavsan"}');
HttpResponse response = http.send(request);
if(response.getStatusCode() != 201) {
System.debug('The status code returned was not expected: ' + response.getStatusCode() + ' ' + response.getStatus());
} else {
System.debug(response.getBody());
}
}
}