All connections require a valid access token. The application uses OpenID Connect (OIDC) via
Keycloak. When a user signs in through the main application, the access token is stored in
sessionStorage and is automatically included in API and SSE requests by the widget.
SSE connections are authenticated with an Authorization: Bearer <jwt> header.
The widget handles this automatically when a token is stored in sessionStorage.
import { fetchEventSource } from '@microsoft/fetch-event-source' fetchEventSource('/api/headlines/stream', { headers: { Authorization: 'Bearer ' + token }, onmessage(event) { console.log(event.data); }, });
Include an Authorization: Bearer <jwt> header. The built-in API client handles this
automatically when a token is stored in sessionStorage.
The easiest way to use the headline widget is via the global headline_listing function:
// Get a reference to a DOM element const root = document.getElementById('headline-listing') // Store token for automatic auth (optional) sessionStorage.setItem('headlines_token', token) // Initialize the widget const widget = headline_listing(root, { criteria: { text_search: 'Fed' }, audio_notifications: true }) // Later, to clean up: widget.cleanup()
import { headline_listing } from '/lib/headline_listing.js' const root = document.getElementById('headline-root') headline_listing(root, { criteria: { text_search: 'Fed' } })
For SolidJS applications, import the component directly:
import { HeadlineListing, HeadlineCriteria } from '/lib/headline_listing.js' function MyComponent() { const criteria = () => ({ text_search: 'Fed' }) return ( <div> <HeadlineListing criteria={criteria} audio_notifications={false} /> </div> ) }
Render a headline widget into the specified DOM element.
| Parameter | Type | Required | Description |
|---|---|---|---|
root |
HTMLElement | Required | The DOM element to render the widget into |
props |
HeadlineListingWidgetProps | Optional | Configuration options for the widget |
WidgetInstance| Property | Type | Description |
|---|---|---|
cleanup() |
function | Removes the widget and cleans up resources |
Configuration options for the headline widget.
| Property | Type | Default | Description |
|---|---|---|---|
criteria |
HeadlineCriteria | {} | Filters and search criteria for headlines |
audio_notifications |
boolean | false | Play a ding sound when new headlines arrive via SSE |
Filter criteria for headline listings. All fields are optional.
| Property | Type | Description |
|---|---|---|
text_search |
string | undefined | Search headlines by text content |
const widget = headline_listing(root)
// Show only headlines containing "Fed" const widget = headline_listing(root, { criteria: { text_search: 'Fed' } })
// Play a sound when new headlines arrive const widget = headline_listing(root, { criteria: { text_search: 'ECB' }, audio_notifications: true })
For SolidJS applications, you can import the component and types directly:
import { HeadlineListing, HeadlineCriteria, HeadlineListingWidgetProps } from '/lib/headline_listing.js' // Use in your component function App() { const criteria = () => ({ text_search: 'Fed' }) const props = { criteria, audio_notifications: true } return <HeadlineListing {...props} /> }
| Export | Type | Description |
|---|---|---|
headline_listing |
function | Framework-agnostic widget initializer |
HeadlineListing |
Component | SolidJS component for direct use |
HeadlineListingWidgetProps |
interface | TypeScript interface for widget props |
HeadlineCriteria |
interface | TypeScript interface for filter criteria |
This demo loads the headline_listing widget. Authentication is required — sign in above to
load the demo.