admin管理员组文章数量:1316974
I am trying to access the different information from the following api:.html and stumped in trying to get data for all the different parameters for the /api/pub/ticker request
Here is the code I have written so far, but i cant seem to get any different info for different parameters and end up getting the same information. For example how would i access the data for neo, using it as a parameter
var request = require('request')
console.log('requesting market data from coinnest');
request('',(err,res,body) =>{
try{
var json = JSON.parse(body);
var markets = [];
console.log(body);
}catch(err){
console.log('coinnest parsing error');
}
});
If someone could help give me some advice in what i am doing wrong it would be appreciated. Thanks
I am trying to access the different information from the following api:https://api.coinnest.co.kr/doc/public.html and stumped in trying to get data for all the different parameters for the /api/pub/ticker request
Here is the code I have written so far, but i cant seem to get any different info for different parameters and end up getting the same information. For example how would i access the data for neo, using it as a parameter
var request = require('request')
console.log('requesting market data from coinnest');
request('https://api.coinnest.co.kr/api/pub/ticker/neo',(err,res,body) =>{
try{
var json = JSON.parse(body);
var markets = [];
console.log(body);
}catch(err){
console.log('coinnest parsing error');
}
});
If someone could help give me some advice in what i am doing wrong it would be appreciated. Thanks
Share Improve this question edited Dec 1, 2017 at 18:51 WasabiCannon asked Dec 1, 2017 at 18:47 WasabiCannonWasabiCannon 1392 gold badges2 silver badges11 bronze badges 3- Which query parameter you wanted to send? – Pavan Vora Commented Dec 1, 2017 at 18:49
- any one besides the one that is default which is btc. In the code above i am trying to query the neo parameter – WasabiCannon Commented Dec 1, 2017 at 18:50
- did you solved it? – Pavan Vora Commented Dec 1, 2017 at 19:06
2 Answers
Reset to default 6This is how you can pass parameters to get request,
var request = require('request')
console.log('requesting market data from coinnest');
let options = {
url: "https://api.coinnest.co.kr/api/pub/ticker",
method: 'GET',
qs: {
coin: 'neo'
}
}
request(options,(err,res,body) =>{
try{
var json = JSON.parse(body);
var markets = [];
console.log(body);
}catch(err){
console.log('coinnest parsing error');
}
});
In above example options.qs
is the query parameter in which you can pass whatever query parameter you want to pass or else you can simply run
request('https://api.coinnest.co.kr/api/pub/ticker?coin=neo',(err,res,body) =>{
try{
var json = JSON.parse(body);
var markets = [];
console.log(body);
}catch(err){
console.log('coinnest parsing error');
}
});
You're not sending any parameters in your GET request, hence you get the response for BTC by default as stated in the API doc.
Send the parameter by appending the URL with ?coin=coinnamehere
The following would give you the data for Ethereum.
request('https://api.coinnest.co.kr/api/pub/ticker?coin=eth',(err,res,body) =>{
try{
var json = JSON.parse(body);
var markets = [];
console.log(body);
}catch(err){
console.log('coinnest parsing error');
}
});
本文标签: javascriptHow to add parameters to a GET request in nodejsStack Overflow
版权声明:本文标题:javascript - How to add parameters to a GET request in node.js? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742009819a2412678.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论