如何使用 feathers js 构建 Rest API?

How build Rest API with feathers js?

我的文件中有 server.js 这个代码:

MongoClient.connect(url).then(db => {
  app.use('/users', service({
    Model: db.collection("Users"),

  }));
});

现在,如果我打开“/users”,就会显示我的所有用户。我想创建服务以通过其 Id 给我一个用户。当我访问“/users/5”时,会给我一个他的 id=5 的用户。请问谁能帮帮我?

这已经内置。MongoDB 在 _id 中使用 ObjectId。因此,如果您从 /users 列表中取出任何 _id 属性 并打开 /users/<_id>,它将显示该特定用户。

有关详细信息,请参阅 basics guide, the services API (and how those map to a REST API) as well as the database adapter common API and the MongoDB adapter documentation