最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to add parameters to a GET request in node.js? - Stack Overflow

programmeradmin2浏览0评论

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
Add a ment  | 

2 Answers 2

Reset to default 6

This 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');
    }
});
发布评论

评论列表(0)

  1. 暂无评论