Skip to content

Instantly share code, notes, and snippets.

@sudikrt
Created September 8, 2017 14:38
Show Gist options
  • Save sudikrt/9064aef3976f663e1adc179d2b62d272 to your computer and use it in GitHub Desktop.
Save sudikrt/9064aef3976f663e1adc179d2b62d272 to your computer and use it in GitHub Desktop.
Http http = new Http ();
HttpRequest req = new HttpRequest ();
req.setEndPoint ('https://th-apex-http-callout.herokuapp.com/animals');
req.setMethod ('POST');
req.setHeader ('Content-Type', 'application/json;charset=UTF-8');
req.setBody ('{"name":"mighty moose _1"}');
HttpResponse response = http.send(req);
if (response.getStatusCode() != 201) {
System.debug('The status code returned was not expected: ' +
response.getStatusCode() + ' ' + response.getStatus());
} else {
System.debug(response.getBody());
}
Http http = new Http ();
HttpRequest req = new HttpRequest ();
req.setEndpoint ('https://th-apex-http-callout.herokuapp.com/animals');
req.setMethod ('GET');
HttpResponse response = http.send(req);
if (response.getStatusCode () == 200) {
Map <String, Object> result = (Map<String, Object>) JSON.deserializeUntyped(response.getBody ());
List<Object> animals = (List<Object>) result.get ('animals');
System.debug('Received Data *****');
for (Object anim : animals) {
System.debug('$$$$$ '+ anim +' %%%%');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment