Rest CallOut in LWC

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.

--

--

--

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

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Webner Solutions

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.

More from Medium

How to deploy the LWC component on a Local Development Server

How to deploy the LWC component on a Local Development Server

Why you should not use the System Administrator profile for Integration Users in Salesforce

God Mode Deactivated

Displaying Account data from another Salesforce org in a Flex card .

Interview Questions on Future Method in Salesforce