Week 1 Answers Question #1 What are the components of an HTTP request? Endpoint – server your trying to call Headers – pass information with request like values to query, or record IDs to delete Body (Payload) Question #2 What are the components of an HTTP response? - Headers - Body – Always used, as opposed to request which could use Get or Delete therefor doesn’t need to use body. But a body is needed to respond to Get Requests with the results of the request. - Status Code – Tells you the results of your request o 200 – Success o 400 – problem request side o 500 – problem server side Question #3 What are the 2 most popular payload formats? - JSON (Java Script Object Notation) – Newer technology Easier to interact with - XML (Extensible Markup Language) – old technology Question #4 Explain JSON format in your own words. Give an example. - JSON is a Map which is a Key and Value. It uses the language of the internet, not Salesforce specific, requires code to transform data to Salesforce. Example Restaurant Order “customer”:{ “firstName” :’Ronald’, “lastName”:’McDonald’, “table”:30 }, “order”:{ “item 1”:’Hamburger’. “item 2”:’Fries’ } Question #5 public class week1HTTPResponse { public week1HTTPResponse() { HttpRequest httpRequest = new HttpRequest(); httpRequest.setMethod('GET'); httpRequest.setEndpoint('https://735ef563-176d-431c-85ce-2cc07056ef03.mock.pstmn.io/payments/link'); Http http = new Http(); HttpResponse response = http.send(httpRequest); System.debug(response.getBody()); // 1 - Deserialize Response Map<String,Object> parsedBody = (Map<String,Object>)JSON.deserializeUntyped(response.getBody()); System.debug('Parsed Body: '+ parsedBody); // 2 - Retrieve Pay Information Map<String,Object> parsedPayer = (Map<String,Object>)parsedBody.get('payer'); System.debug('Parsed Payer: '+ parsedPayer); // 2.1 - Retrieve Payment Link String payerLink = (String) parsedPayer.get('link');