Problem
Some of the data a page needs does not live in Salesforce. It sits behind a third party’s REST API, and users on Experience Cloud sites and Lightning pages need to see it live, not as a stale copy.
What I built
REST integrations with custom JS controllers and wrappers that fetch external data and render it inside Experience Cloud and Lightning pages.
How it works
The browser never talks to the third party, so endpoints and secrets stay out of client code.
The pattern: the browser never talks to the third party. The component calls an Apex method, and Apex calls the REST API, so endpoints and secrets stay out of client code.
Wrap the response. An Apex wrapper class deserialises the external JSON into a typed shape the component can rely on. The wrapper also normalises the parts that vary (missing fields, renamed properties), so the UI does not branch on the third party’s quirks.
A thin JS controller. The LWC’s controller owns loading, error and empty states and calls the Apex method imperatively, so the page shows something sensible when the API is slow or down.
public with sharing class ExternalQuoteClient {
public class Quote {
@AuraEnabled public String symbol;
@AuraEnabled public Decimal price;
@AuraEnabled public String currencyCode;
}
@AuraEnabled(cacheable=true)
public static Quote get(String symbol) {
HttpRequest req = new HttpRequest();
req.setEndpoint('callout:Market_Data/v1/quote/' + EncodingUtil.urlEncode(symbol, 'UTF-8'));
req.setMethod('GET');
req.setTimeout(8000);
HttpResponse res = new Http().send(req);
if (res.getStatusCode() != 200) {
throw new AuraHandledException('The data provider returned ' + res.getStatusCode() + '.');
}
Map<String, Object> raw = (Map<String, Object>) JSON.deserializeUntyped(res.getBody());
Quote q = new Quote();
q.symbol = (String) raw.get('symbol');
q.price = Decimal.valueOf(String.valueOf(raw.get('price')));
q.currencyCode = raw.containsKey('currency') ? (String) raw.get('currency') : 'USD';
return q;
}
}