Rest CallOut can be made in Salesforce in two ways:
- Server-side controller (Apex Class)
- 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:-
Rest.js
Rest. js-meta.xml
OUTPUT:-
In this callout, whenever we hit the API, I call the random joke API, which returns a new joke every time.