Arun Kumar
BBC News LWC
2022 / Salesforce Project
Requirements
1. Develop a Lightning Web Component that displays the top ten news articles from BBC News.
2. Create a lighting tab and display this component in this tab.
Solution
To bring news articles from the BBC News website to our lightning web component, we have to use the BBC News API. I looked to see if the official BBC API was available, but I couldn’t find any. In my search for an API to meet this requirement, I came across the fantastic NewsAPI.org API, and this API service was a perfect fit.
There are two ways of making a callout from the lightning web component.
- From javascript controller
- Using Apex code
Because NewsAPI does not support javascript callouts for free developer accounts, I used the second option and formed a callout with Apex code.
HTTP Callout architecture

To authenticate the NewsAPI, I used the Salesforce Named Credentials platform feature. NewsAPI API keys can be obtained by registering on their website.

Here’s how I made a call to news API from the Apex code.

The Apex code above returns the API response to the LWC javascript controller, and the javascript controller class parses the news article data and displays it on the LWC HTML page. All project code can be found in the Github repository, which is linked below.

Quick News Lightning Component
News App | It displays the latest news articles from different news sources.