Skip to content

ProjectREST integrations on Experience Cloud

  • Industry

    Cross-industry

  • Cloud

    Experience Cloud, Lightning Web Components

  • Role

    LWC and Apex developer

  • Period

    Independent, 2023 – present

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

PatternCalling a third-party REST APIThe approach, not a client’s system
Salesforceimperative callHTTPLWC and JS controllerloading, error, empty statesApex callout andwrappertyped, normalised responseExternal REST APIthird party

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.

Illustrative: rebuilt for this site, not client codeExternalQuoteClient.cls
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;
  }
}

Built with the Salesforce Lightning Design System. Not affiliated with Salesforce.

App Launcher