Skip to main content

Custom Implementation

This section describes the API for importing news from an external resource. This API provides access to news via a REST interface.

API Endpoint

GET /api/news

This endpoint returns a list of news items.

Query Parameters

ParameterTypeRequiredDescription
limitnumberNoLimit the number of news items returned
offsetnumberNoOffset for pagination

Response Format

[
{
"id": 1,
"title": "News Title",
"description": "News Content",
"createdAt": "2024-01-01T12:00:00.000Z"
},
{
"id": 2,
"title": "Another News",
"description": "Text of another news item",
"createdAt": "2024-01-02T15:30:00.000Z"
}
]

Response Field Descriptions

FieldTypeDescription
idnumberUnique news identifier
titlestringNews title
descriptionstringFull news text
createdAtstringPublication date in ISO format

Examples

// Example of fetching news using Fetch API
async function getNews(limit = 10, offset = 0) {
try {
const response = await fetch(`https://your-api.com/api/news?limit=${limit}&offset=${offset}`);

if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}

const newsItems = await response.json();

console.log(`Received ${newsItems.length} news items`);

// Processing received news
newsItems.forEach(news => {
console.log(`${news.title} (${new Date(news.createdAt).toLocaleDateString()})`);
console.log(news.description);
console.log('---');
});

return newsItems;
} catch (error) {
console.error('Error fetching news:', error);
return null;
}
}

// Usage
getNews(5, 0).then(result => {
// Additional processing of the result
});

Integration with GML

To integrate the News API with GML:

  1. Ensure your API is running and accessible over the network.
  2. In the GML control panel, go to the integrations section.
  3. Select "Import news from an external resource".
  4. Provide the URL of your API that returns news in the format described above.
  5. Save the settings.

After successful integration, news will automatically appear in the GML launcher. Note that GML expects an array of objects with fields id, title, description, and createdAt. If your API returns data in a different format, you will need to create a middleware layer to transform the data.