Happy Friday! My Homework Question #1 What are the components of an HTTP request? Request Type,Endpoint, Header, Payload (if post request type) Question #2 What are the components of an HTTP response? Header, Response Body, Status code Question #3 What are the 2 most popular payload formats? JSON and xml (SOAP API, Enterprise/Partner WSDL) Question #4 Explain JSON format in your own words. Give an example. JSON format represents a map of key value pairs where the key is always a string and the value can be a number, string,boolean, object or other nested map, list. JSON Example: { "name": "John Doe", "age": 30, "email": "
[email protected]", "skills": ["Java", "Apex", "Python"], "address": { "street": "123 Main St", "city": "Springfield", "country": "USA" } } Question #5 HttpRequest request = new HttpRequest(); request.setMethod('GET'); request.setEndpoint('https://735ef563-176d-431c-85ce-2cc07056ef03.mock.pstmn.io/payments/link'); Http http = new Http(); HttpResponse response = http.send(request); Integer statusCode = response.getStatusCode(); if(statusCode >=200 && statusCode < 300){ System.debug('Sucess: '+statusCode); } else{ System.debug('Failure: '+statusCode); } String responseBody = response.getBody(); Map<String,Object> responseMap = (Map<String,Object>) JSON.deserializeUntyped(responseBody); Map<String,Object> transactionMap = (Map<String,Object>) responseMap.get('transaction'); if(transactionMap == null){ System.debug('No Tranaction Available'); return; } else{ Map<String,Object> detailsMap = (Map<String,Object>) transactionMap.get('details'); if(detailsMap == null){ System.debug('No Transaction Details Available'); return; } else{ String ip = (String) detailsMap.get('IP'); System.debug(ip); } }