Created
February 26, 2026 11:40
-
-
Save zeshanshani/5ba4bd6bfae45908f2c26b072487b597 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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