Reputation: 3515
I am developing a web app using node.js and express.js.
Here is the working cURL command that I would like to convert to javascript using the node-fetch
module.
curl -X GET -H "X-Parse-Application-Id: APPLICATION_ID" -H "X-Parse-REST-API-Key: restAPIKey" -G --data-urlencode "count=1" --data-urlencode "limit=0" http://localhost:1337/parse/classes/GCUR_LOCATION
How to get the data-urlencode params into the following snippet to complete the javascript to do the job?
fetch('http://localhost:1337/parse/classes/GCUR_LOCATION', { method: 'GET', headers: {
'X-Parse-Application-Id': 'APPLICATION_ID',
'X-Parse-REST-API-Key': 'restAPIKey'
}});
Upvotes: 1
Views: 1958
Reputation: 31761
Use querystring
.
const querystring = require('querystring');
const query = querystring.stringify({ count: 1, limit: 0 });
const url = `http://localhost:1337/parse/classes/GCUR_LOCATION?${query}`;
fetch(url, {
method: 'GET',
headers: {
'X-Parse-Application-Id': 'APPLICATION_ID',
'X-Parse-REST-API-Key': 'restAPIKey'
}
});
Upvotes: 2