Search code examples
meteorrestivus

Restivus return HTML template?


I'm trying to make an api for my METEOR application. I looked at https://atmospherejs.com/simple/rest and https://atmospherejs.com/xcv58/collection-api but that didn't work. Now i'm on restivus : https://atmospherejs.com/nimble/restivus

The problem that i got is that when i'm trying to call the api, it always return my HTML template, otherwise i need a json response...

This is my code for the api =>

In server.js :

// Global API configuration
    var Api = new Restivus({
        apiPath: 'api/',
        auth: {
          token: 'auth.apiKey',
          user: function () {
            return {
              userId: this.request.headers['user-id'],
              token: this.request.headers['login-token']
            };
          }
        },
        defaultHeaders: {
          'Content-Type': 'application/json'
        },
        onLoggedIn: function () {
          console.log(this.user.username + ' (' + this.userId + ') logged in');
        },
        onLoggedOut: function () {
          console.log(this.user.username + ' (' + this.userId + ') logged out');
        },
        prettyJson: true,
        useDefaultAuth: true,
        version: 'v1'
    });

    Api.addCollection('coupons');

When i try to do curl on http://localhost:3000/api/v1/login/ with some username and password data, it return me all my html template...

Someone know the solution or already have this problem ?

Thanks for your future answers :)


Solution

  • The problem is that you're using the set of API options that the docs warn against using. Check the comment directly above the code here. If you want to copy and paste some code to get started, you can use the code from the quick start example. All you need is the following to get the API you're looking for:

    var Api = new Restivus({
      useDefaultAuth: true,
      version: v1
    });
    
    Api.addCollection('coupons');