【发布时间】:2015-12-16 21:14:23
【问题描述】:
我尝试创建一个模型,并连接到我的 API 测试服务器。
这是 REST 数据源配置:
"postsREST": {
"name": "postsREST",
"connector": "rest",
"operations": [{
"template": {
"method": "GET",
"url": "http://localhost:3001/posts"
},
"functions": {
"find": []
}
}, {
"template": {
"method": "POST",
"url": "http://localhost:3001/posts",
"headers": {
"accept": "application/json",
"content-type": "application/json"
},
"query": {
"title": "{^title}",
"author": "{^author}"
},
"body": {
"title": "{^title}",
"author": "{^author}"
}
},
"functions": {
"create": [
"title",
"author"
]
}
}]
}
问题是,当我使用资源管理器时,生成的请求 url 是这样的:
http://localhost:3000/api/posts/create?title=f&author=f
代替:
http://localhost:3000/api/posts
我做错了什么?也许有新的文档?
谢谢。
【问题讨论】:
-
我注意到您在文件中使用端口 3001 (
localhost:3001),在浏览器中使用端口 3000,是不是错字? -
REST 数据源连接器旨在供您的模型用于访问外部 API……这似乎是以循环方式访问同一模型。你到底想完成什么?
-
当然是外部的。它只是例如。从代码中可以看出,问题在于 post url 的行为类似于 get。 url是本地的(3000端口),3001是外部的。
标签: node.js rest loopbackjs strongloop