Rest CallOut in LWC

Webner Solutions
3 min readFeb 7, 2022
Rest CallOut in LWC
Rest CallOut in LWC

Rest CallOut can be made in Salesforce in two ways:

  1. Server-side controller (Apex Class)
  2. Client-side controller (Js Controller)
  • Server-side controller (Apex Class): We can make an API callout from Apex , which provides support for REST and SOAP callouts. Before making callouts from the apex, we have to add our endpoint in “Remote Site Setting”.
  • Client-side controller: The Lightning Web Component supports modern Javascript. We can make rest call-outs from the JS controller. Before making call-outs from the JS controller, we have to add our endpoint in “Content Security Policies”. It prevents cross-site scripting and also prevents code injection attacks.

To add endpoints in CSP, search for CSP in the quick find box and click “CSP Trusted Sites.”

Rest.html:-

OUTPUT:-

In this callout, whenever we hit the API, I call the random joke API, which returns a new joke every time.

Webner Solutions is a Software Development company focused on developing Insurance Agency Management Systems, Learning Management Systems and Salesforce apps. Contact us at dev@webners.com for your Insurance, eLearning and Salesforce applications.

Originally published at https://blog.webnersolutions.com on February 7, 2022.

--

--

Webner Solutions

Our team in Salesforce is very strong, with in-depth knowledge of Salesforce classic and Lightning development as well as the Service cloud.