Skip to content

Instantly share code, notes, and snippets.

@zeshanshani
Created February 26, 2026 11:40
Show Gist options
  • Select an option

  • Save zeshanshani/5ba4bd6bfae45908f2c26b072487b597 to your computer and use it in GitHub Desktop.

Select an option

Save zeshanshani/5ba4bd6bfae45908f2c26b072487b597 to your computer and use it in GitHub Desktop.
// Fetch article list with filters using fetch()
async function fetchArticles({ token, region = 'USA', keyword, sectors = [], subregions = [], page = 1 }) {
const url = new URL('https://web-news-service.greenstreet.com/api/articles');
url.searchParams.set('region', region);
if (keyword) url.searchParams.set('keyword', keyword);
sectors.forEach((s) => url.searchParams.append('sectors', String(s)));
subregions.forEach((r) => url.searchParams.append('subregions', String(r)));
if (page) url.searchParams.set('page', String(page));
const res = await fetch(url.toString(), {
headers: { Authorization: `Bearer ${token}` },
});
if (!res.ok) throw new Error(`Request failed: ${res.status}`);
return res.json();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment