Anis D
Anis D

Reputation: 761

Meteor REST API access

I am trying to add a REST API to my Meteor application using Restivus

I putted the following code in server folder of my Meteor application. Currently, I am trying to get the URL parameters.

      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
          }
      }
    }
  });

I got this response

{
"status": "error"
"message": "API endpoint does not exist"
}

to my request:

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

Upvotes: 1

Views: 533

Answers (1)

MrE
MrE

Reputation: 20798

the way you wrote the url login/:id/:password means it is expecting the url to be http://localhost:3000/api/login/BGrZbGtKZZQYr9jDR/myPassword

However in your code, you are looking at the queryParams not urlParams:

var id = this.queryParams.id;
var password = this.queryParams.password;

You should choose one or the other:

use the code:

var id = this.urlParams.id;
var password = this.urlParams.password;

with the /login/:id/:password URL,

or use the route with just /login and pass the params as query params to use as you described:

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
          }
      }
    }
  });

Upvotes: 4

Related Questions