如何从 express js 迁移到 feathers js 服务器?

How to migrate from express js to feathers js server?

我通过 express js 构建了一个 api rest 到 post 我服务器中的一个数据。

app.post("/register", function(request, response){
   var username = request.body.username;
});

我如何使用 feathersjs 做到这一点?以及如何从我的 reactjs 应用程序中调用它?

羽毛是drop-in replacement for Express。这意味着您可以将 const app = express(); 替换为 const app = feathers() 并且一切都将正常工作,因此您在上面显示的内容也可以使用 Feathers 来完成。

实现此目的的真正 Feathers 方法是通过 services which - with the other important concepts - are described in the basics guide

有预构建服务for several databases (which can be customized through hooks) but you can always create your own service. It is important to note that Feathers services - unlike the Express middleware you showed - will be available via HTTP (REST) and websockets (which also gets you real-time events). See here how service methods map to REST endpoints

您在 Feathers 中的示例如下所示:

app.use('/register', {
  create(data, params) {
    // data is the request body e.g.
    // data.username

    // Always return a promise with the result data
    return Promise.resolve(data);
  }  
});