Created
September 8, 2017 14:38
-
-
Save sudikrt/9064aef3976f663e1adc179d2b62d272 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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