Reputation: 2610
SO I started using the node.js request module to make request to the youtube api. I could make the query string of the below link myself, but I'm pretty sure there is a shortcut. Does anyone know it?
The youtube API link
'https://www.googleapis.com/youtube/v3/search?part=snippet&q=black%20panther&key=AIzaSyD4shfocwn-Ed3Feuoo9fG3d2K2GjHmKeI&maxResults=20&order=viewCount&type=video'
So, I'm looking for a shortcut to add the above query string to my http request
request('https://www.googleapis.com/youtube/v3/search', function (error, response, body) {
});
Upvotes: 3
Views: 2269
Reputation: 4073
You can use querystring
in node js just pass a json object with query parameters and it will convert it to query string
const querystring = require('querystring');
const obj = { part: 'snippet', q: 'black' };
const urlQueryString = querystring.stringify(obj);
request('https://www.googleapis.com/youtube/v3/search?' + urlQueryString ,
function (error, response, body) {
});
Upvotes: 5