Created
November 4, 2022 16:38
-
-
Save emoran/ddb70039e81df72d38abfcb16c043aa0 to your computer and use it in GitHub Desktop.
This file contains 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 RestServiceConsumerDW { | |
public static void consume(){ | |
Http http = new Http(); | |
HttpRequest request = new HttpRequest(); | |
request.setEndpoint('https://techcrunch.com/wp-json/wp/v2/posts?per_page=2&context=embed'); | |
request.setMethod('GET'); | |
HttpResponse response = http.send(request); | |
// If the request is successful, parse the JSON response. | |
if(response.getStatusCode() == 200) { | |
Map<String, Object> parameters = new Map<String, Object>(); | |
parameters.put('incomingJson', response.getBody()); | |
Dataweave.Script script = Dataweave.Script.createScript( | |
'json2sObjects' | |
); | |
DataWeave.Result result = script.execute(parameters); | |
System.debug('DW RESPONSE: '+ result.getValueAsString()); | |
List<Lead> lead = (List<Lead>)JSON.deserializeUntyped(result.getValueAsString()); | |
System.debug('lead: '+lead); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment