【发布时间】:2015-02-18 21:35:28
【问题描述】:
所以我有流星运行,我希望公开一个 REST API。我决定选择restivus,因为它对我来说似乎更干净、更灵活。
所以我的基本代码是:
if (Meteor.isServer) {
Meteor.startup(function () {
// Sensors = new Meteor.Collection('sensor');
Restivus.configure({
useAuth: false,
prettyJson: false
});
Restivus.addCollection("sensor", {
defaultOptions: {},
});
});
}
我可以使用以下方法很好地查询它:
$ curl -X GET http://localhost:3000/api/sensor
{"status":"success","data":[{"_id":{"_str":"00000000236668afaf952dee"},"ts":1424246899,"temp":28,"humidity":33}]}
hmm...所以我手动输入的“_id”(而不是让 mongo 为我设置)在输出中看起来有点奇怪;不过好吧,我猜是ObjectId()。但是,当我使用 GET 时,它会失败:
$ curl -X GET http://localhost:3000/api/sensor/00000000236668afaf952dee
{"status":"fail","message":"项目未找到"}
我做错了什么?
【问题讨论】:
-
另外,文档中有一个错误,现已修复;所以你声明为
defaultOptions: {}的对象实际上应该命名为routeOptions,这并不重要,因为你实际上没有设置任何选项。只是想指出这一点,以免它在其他地方咬你。
标签: mongodb api rest http meteor