Posts

Showing posts with the label Webservice callout from LWC

HTTP callout from LWC

Image
HTTP callout from Lightning Web Components? Is it similar to Lightning (Aura) components? Or is something better available in modern JavaScript? Do we still require Apex to make the callout? Or can we handle it all on the client side itself? Have similar questions in your mind? Then continue reading this blog post. Today, we will see how to make an HTTP callout from a Lightning Web Component. Good news - we do not require any apex class to make the callout. In the JavaScript controller of our lightning web component, we can easily make the web service callout by making use of the fetch method. For this example, we will use the free API provided by Crypto Compare . The API returns the response in JSON format, which we will parse and feed to the HTML file. The component will make the HTTP callout to bring in the price of the top 10 cryptocurrencies and display them in a lightning card. To make the callout from the Lightning web component, first, we need to add the endpoint URL in