0

I just started using restify and tries to build a very simple JSONClient and fails on the first step.

var restify = require('restify');

var client = restify.createJsonClient({
    url: 'http://api.bgm.tv'
});
client.get('/calendar', function(err, req, res, obj) {
    console.log('%j', obj);
});

This pieces of code returns {} with a status code 200

If you check http://api.bgm.tv/calendar in browser or curl it seems to be a legit json GET Rest API and does not require auth or anything else.

I tried other API such as stackoverflow api it works perfectly, so I assume something wrong with the server side?

If anyone can try to run it and help me point out what might went wrong would be very appreciated.

Mark Ni
  • 2,383
  • 1
  • 27
  • 33
  • I ran your code and had no issue getting the JSON. I am using node v0.10.12 on a MAC. and v 2 of restify. Try updating your versions? – kpasgma Jul 04 '13 at 13:33

2 Answers2

1

I runned your example node code and got a proper response (the same you get when browsing).

You probably have some version problem or a console.log size limitation.

Try using: console.log(obj[0]); it should print only the first object in the json.

I'm using node v0.8.9 and restify v2.4.1 on a mac.

andresgottlieb
  • 920
  • 10
  • 18
  • I guess it's a version problem then. I'm using node v0.10.4, restify 2.4.1 and mac. I can get the result using node's "http" module, so it shouldn't be a console limitation. Thanks your help. – Mark Ni Apr 13 '13 at 21:25
  • Thanks for the information. Still, I think there won't be much I can do if other people can't reproduce it and syntax is correct. – Mark Ni Apr 13 '13 at 21:57
0

Yeah, when I use the Postman plugin for Chrome and do a GET request to http://api.bgm.tv/calendar I get:

[
    {
        "weekday": {
            "en": "Mon",
            "cn": "星期一",
            "ja": "月耀日",
            "id": 1
        },
        "items": [
            {
                "id": 46458,
                "url": "http://bgm.tv/subject/46458",
                "type": 0,
                "name": "アイカツ! -アイドルカツドウ!-",
                "name_cn": "偶像活动",
                "summary": "",
                "eps": 0,
                "air_date": "2012-10-08",
                "air_weekday": 1,
                "images": {
                    "large": "http://lain.bgm.tv/pic/cover/l/db/7f/46458_8mM39.jpg",
                    "common": "http://lain.bgm.tv/pic/cover/c/db/7f/46458_8mM39.jpg",
                    "medium": "http://lain.bgm.tv/pic/cover/m/db/7f/46458_8mM39.jpg",
                    "small": "http://lain.bgm.tv/pic/cover/s/db/7f/46458_8mM39.jpg",
                    "grid": "http://lain.bgm.tv/pic/cover/g/db/7f/46458_8mM39.jpg"
                },
                "collection": {
                    "wish": 0,
                    "collect": 0,
                    "doing": 44,
                    "on_hold": 0,
                    "dropped": 0
                }
            },
            {
                "id": 57150,
                "url": "http://bgm.tv/subject/57150",
                "type": 0,
                "name": "LINE OFFLINE ~サラリーマン~",
                "name_cn": "离线LINE - 上班族 -",
                "summary": "",
                "eps": 0,
                "air_date": "2013-01-07",
                "air_weekday": 1,
                "images": {
                    "large": "http://lain.bgm.tv/pic/cover/l/71/28/57150_Kz171.jpg",
                    "common": "http://lain.bgm.tv/pic/cover/c/71/28/57150_Kz171.jpg",
                    "medium": "http://lain.bgm.tv/pic/cover/m/71/28/57150_Kz171.jpg",
                    "small": "http://lain.bgm.tv/pic/cover/s/71/28/57150_Kz171.jpg",
                    "grid": "http://lain.bgm.tv/pic/cover/g/71/28/57150_Kz171.jpg"
                },
                "collection": {
                    "wish": 0,
                    "collect": 0,
                    "doing": 206,
                    "on_hold": 0,
                    "dropped": 0
                }
            },
            {
                "id": 58709,
                "url": "http://bgm.tv/subject/58709",
                "type": 0,
                "name": "ハヤテのごとく! Cuties",
                "name_cn": "旋风管家 Cuties",
                "summary": "",
                "eps": 0,
                "air_date": "2013-04-08",
                "air_weekday": 1,
                "images": {
                    "large": "http://lain.bgm.tv/pic/cover/l/15/28/58709_H7uj8.jpg",
                    "common": "http://lain.bgm.tv/pic/cover/c/15/28/58709_H7uj8.jpg",
                    "medium": "http://lain.bgm.tv/pic/cover/m/15/28/58709_H7uj8.jpg",
                    "small": "http://lain.bgm.tv/pic/cover/s/15/28/58709_H7uj8.jpg",
                    "grid": "http://lain.bgm.tv/pic/cover/g/15/28/58709_H7uj8.jpg"
                },
                "collection": {
                    "wish": 0,
                    "collect": 0,
                    "doing": 219,
                    "on_hold": 0,
                    "dropped": 0
                }
            },

...and a bunch more, but the body limit to answers on SO is 30,000 characters.

jefflunt
  • 33,527
  • 7
  • 88
  • 126