Skip to content

Instantly share code, notes, and snippets.

@willyanmarques
Last active July 24, 2019 22:03
Show Gist options
  • Save willyanmarques/a91d4194c8960a88bc1500e4ba7218c4 to your computer and use it in GitHub Desktop.
Save willyanmarques/a91d4194c8960a88bc1500e4ba7218c4 to your computer and use it in GitHub Desktop.
public class REST {
public static void calloutAPI(){
try{
Http http = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint('https://reqres.in/api/users?page=1');
req.setMethod('GET');
HttpResponse res = http.send(req);
if(res.getStatusCode() == 200){
//Aqui vamos trabalhar do JSON
} else {
System.debug('Falha ao obter dados da API. Status code: ' + res.getStatusCode());
}
}
catch(Exception e){
System.debug('Exception! Mensagem: ' + e.getMessage() + ' Linha: ' + e.getLineNumber());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment