Skip to content

Component: News Widget

Raymond Vo edited this page Dec 13, 2018 · 1 revision

Overview

The News Widget is a component that makes an api request to an RSS feed of Veterans Affairs news and retrieves/formats the data for display. It is a small widget included in the Dashboard page, designed to display a preview of the most recent news article from the RSS feed as well as a link to view the full article and a link to view the News Page with more articles. The News Page is just a page with a list of the previews of the 20 most recent articles from the feed.

Getting data from the RSS feed

The RSS provider makes an api call to an online RSS to JSON converter (www.rss2json.com) to get the chosen xml file and parse it into JSON. The variables:

const RSS_URL: any = '';
const API: any = '';
const count: any = ;
const API_URL: any = '';

are used to set the params for the http.get request, however, they aren't necessarily being used for now. Instead the params are set by:

const params = { params: new HttpParams().set('rss_url', 
                 'https://www.va.gov/health/NewsFeatures/news.xml').set('api_key', 
                 'l7cijr37lmx6omnmg74t5wpzpbdrtc7oagvbewja').set('order_by', 'pubDate').set('order_dir', 
                 'desc').set('count', '20')}

The order of the articles were oldest to newest, so the 'order_dir' had to be set to 'desc' in order to pull the most recent article first.

Parsing the Data into Format-able Content

In the component's .ts file, the getData() function uses the .subscribe method to get the data from the api and iterates through each object, formatting the data we need to display. Because the summary that is returned from the api includes the text content, reference link, and picture as one variable, the information is parsed and created as separate variables for formatting purposes.

Limitations

rss2json.com may not be up forever, so the functionality is dependent on if the server is still working. The rss feed chosen (My Health Vet) has not been updated for months so we may want to replace the feed with something more active. However, the Veterans Affairs website does not provide any worthy rss feeds that are still regularly updated.