[go: nahoru, domu]

Skip to content

Instantly share code, notes, and snippets.

@harihara6
Created March 26, 2022 13:32
Show Gist options
  • Save harihara6/3b53e415733c89ed46eba193ee10247c to your computer and use it in GitHub Desktop.
Save harihara6/3b53e415733c89ed46eba193ee10247c to your computer and use it in GitHub Desktop.
Get news from bing API
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