简体   繁体   English

Restangular - 如何使用GET方法访问此API?

[英]Restangular - How do I reach this API using GET method?

How do I make a GET call to a REST API with the below signature: 如何使用以下签名对REST API进行GET调用:

http://www.example.com/hierarchies/nodes/1005/parents

I am trying to call the API like so: 我试图像这样调用API:

var service = Restangular.all('hierarchies');

return service.one('nodes', id).all('parents').get();

But it throws the following error: 但它会引发以下错误:

TypeError: Cannot read property 'toString' of undefined

The API call(if successful) would respond in a nested format as below: API调用(如果成功)将以嵌套格式响应,如下所示:

{
    name: "",
    children: [
        {
            name: "",
            children: [
                {
                    name: "",
                    children: [
                        ..
                    ]
                }
            ]
        }
    ]
}

Thanks in advance! 提前致谢!

I think if you use all as the last part of the builder, a list is expected and you should use getList instead of get . 我认为如果你使用all作为构建器的最后一部分,则需要一个列表,你应该使用getList而不是get However the object you are expecting does not look like a list, so you could change the last part of your builder to just use one without the second parameter and then a single object as the response will be expected. 但是你期望看起来并不像一个清单,这样你就可以改变你的建设者只使用最后一部分的对象one没有第二个参数,然后一个对象作为响应将有望。

service.one('nodes', 5).one('parents').get().then(function(response) {
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM