Rest CallOut in LWC

Author - Webner
7.02.2022
|
0 Comments
||

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.”
CSP Trusted Sites | Rest Call Out

Rest.html:-
Resthtml | RestCallOut
Rest.js
Rest js | RestCallOut
Rest. js-meta.xml
js meta xml | RestCallOut

OUTPUT:-

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

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.

Leave a Reply

Your email address will not be published.