Created
March 26, 2022 13:32
-
-
Save harihara6/3b53e415733c89ed46eba193ee10247c to your computer and use it in GitHub Desktop.
Get news from bing API
This file contains 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
import axios from "axios"; | |
import BingResponse from "./Bing"; | |
export async function getBingNews() : Promise<BingResponse[]> { | |
let res : BingResponse[]= [] | |
await axios.get('https://api.bing.microsoft.com/v7.0/news/search',{ | |
params : { | |
q: 'cricket', | |
count: 10, | |
freshness: 'Month', | |
safeSearch: "Strict" | |
}, | |
headers : { | |
'Ocp-Apim-Subscription-Key': '<your bing key>' | |
} | |
}).then(r=>{ | |
res = r.data.value as BingResponse[] | |
}).catch(error => { | |
console.error(error) | |
return []; | |
}); | |
return res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment