Creating a Remote Site Setting and Creating an API Callout #inSalesforce
Setup | Remote Site Settings | New Remote Site | Enter the Remote Site Name (like Callout) and URL(like https://th-apex-http-callout.herokuapp.com/animals/) | Select Active | Save
Create a Class like:
Public class calloutGETClass{
Public string getContent(String url){
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint('https://th-apex-http-callout.herokuapp.com/animals/');
req.setMethod('GET');
HttpResponse res= h.send(req);
return res.getBody();
//system.debug('getResponse'+res.getBody());
}
}
Public string getContent(String url){
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint('https://th-apex-http-callout.herokuapp.com/animals/');
req.setMethod('GET');
HttpResponse res= h.send(req);
return res.getBody();
//system.debug('getResponse'+res.getBody());
}
}
Test in Anonymous Window
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint('https://th-apex-http-callout.herokuapp.com');
req.setMethod('GET');
HttpResponse res= h.send(req);
//return res.getBody();
system.debug('getResponse'+res.getBody());
HttpRequest req = new HttpRequest();
req.setEndpoint('https://th-apex-http-callout.herokuapp.com');
req.setMethod('GET');
HttpResponse res= h.send(req);
//return res.getBody();
system.debug('getResponse'+res.getBody());
Check logs for the response
Visual: https://www.youtube.com/watch?v=Qr0avzLZC5w
Comments
Post a Comment