Meteor REST API访问

Meteor REST API访问,rest,meteor,meteor-restivus,Rest,Meteor,Meteor Restivus,我正在尝试使用添加RESTAPI到我的Meteor应用程序中 我将以下代码放在Meteor应用程序的服务器文件夹中。目前,我正在尝试获取URL参数 var Api = new Restivus({ useDefaultAuth: true, prettyJson: true }); Api.addRoute('login/:id/:password', {authRequired: true}, { get:{ a

我正在尝试使用添加RESTAPI到我的Meteor应用程序中

我将以下代码放在Meteor应用程序的服务器文件夹中。目前,我正在尝试获取URL参数

      var Api = new Restivus({
        useDefaultAuth: true,
        prettyJson: true
      });

    Api.addRoute('login/:id/:password', {authRequired: true}, {
    get:{
    action: function(){
      var id = this.queryParams.id;
      var password = this.queryParams.password;
          return {
          id: id,
          password: password
          }
      }
    }
  });
我得到了这样的回应

{
"status": "error"
"message": "API endpoint does not exist"
}
应我的请求:

http://localhost:3000/api/login?id=BGrZbGtKZZQYr9jDR&password=myPassword

您编写url
login/:id/:password
的方式意味着它希望url
http://localhost:3000/api/login/BGrZbGtKZZQYr9jDR/myPassword

但是,在代码中,您看到的是
queryParams
而不是
urlparms

var id = this.queryParams.id;
var password = this.queryParams.password;
您应该选择其中一个:

使用以下代码:

var id = this.urlParams.id;
var password = this.urlParams.password;
使用
/login/:id/:password
URL

或者使用带有
/login
的路由,并将参数作为查询参数传递,以便按照您的描述使用:

http://localhost:3000/api/login?id=BGrZbGtKZZQYr9jDR&password=myPassword

var Api = new Restivus({
        useDefaultAuth: true,
        prettyJson: true
      });

    Api.addRoute('login', {authRequired: true}, {
    get:{
    action: function(){
      var id = this.queryParams.id;
      var password = this.queryParams.password;
          return {
          id: id,
          password: password
          }
      }
    }
  });

您编写url
login/:id/:password
的方式意味着它希望url
http://localhost:3000/api/login/BGrZbGtKZZQYr9jDR/myPassword

但是,在代码中,您看到的是
queryParams
而不是
urlparms

var id = this.queryParams.id;
var password = this.queryParams.password;
您应该选择其中一个:

使用以下代码:

var id = this.urlParams.id;
var password = this.urlParams.password;
使用
/login/:id/:password
URL

或者使用带有
/login
的路由,并将参数作为查询参数传递,以便按照您的描述使用:

http://localhost:3000/api/login?id=BGrZbGtKZZQYr9jDR&password=myPassword

var Api = new Restivus({
        useDefaultAuth: true,
        prettyJson: true
      });

    Api.addRoute('login', {authRequired: true}, {
    get:{
    action: function(){
      var id = this.queryParams.id;
      var password = this.queryParams.password;
          return {
          id: id,
          password: password
          }
      }
    }
  });

由于查询参数与参数不同,请尝试
http://localhost:3000/api/login/BGrZbGtKZZQYr9jDR/myPassword
由于查询参数与参数不同,请尝试
http://localhost:3000/api/login/BGrZbGtKZZQYr9jDR/myPassword