Last active
July 25, 2019 01:44
-
-
Save willyanmarques/28f6a69e4678ecb1c5a27286a5516bb8 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
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