Skip to content

Instantly share code, notes, and snippets.

@willyanmarques
Last active July 25, 2019 01:44
Show Gist options
  • Save willyanmarques/28f6a69e4678ecb1c5a27286a5516bb8 to your computer and use it in GitHub Desktop.
Save willyanmarques/28f6a69e4678ecb1c5a27286a5516bb8 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());
}
}
//Classes wrapper
public class RestModel {
public List<DataModel> data = new List<DataModel>();
}
//Modelo do objeto que vamos receber na lista JSON
public class DataModel {
public Integer id;
public String email;
public String first_name;
public String last_name;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment