2

I imported restivus using :

meteor add nimble:restivus

And while using Restivus I encounter this error on meteor startup :

"Cannot find name 'Restivus' ".

I can although GET requests but I wonder if it impacts the behavior of the app.

Here is the code used :

 if (Meteor.isServer) {
        // Global API configuration
        var Api = new Restivus({
            apiPath: 'api/',
            prettyJson: true
        });
    }

When receiving POSTs my request.body and my bodyParams are empty :

Api.addRoute(':id/test', {
        post: function () {
            var id = this.urlParams.id;
            console.log("Body contains : ");
            console.log(this.bodyParams);
            return {
              status: 'success',
              url  : 'post test from id: '+id,
              body : this.bodyParams
            };
        }
    });

Does anyone know how to make this error disappear and if this is linked to the POST body problem ?

3 Answers3

1

If you use Meteor 1.4+ you can try to import Restivus to your file with something like this:

import Restivus from 'nibmle:restivus';
Maxim Bureac
  • 17
  • 2
  • 8
1

The problem with post body being empty was caused by the request I made : I wasn't specifying the Content-type header.

Once I specified the "Content-Type": "application/json" it worked.

The "Cannot find 'Restivus' " Error is still here though.

0

Your code looks ok. Here is some code from a server-only file that I am using:

// Global API configuration
  var Api = new Restivus({
    useDefaultAuth: true,
    prettyJson: true,
    apiPath: 'restAPI/',
    defaultHeaders: { 'Content-Type': 'application/json;encoding="UTF-8"' }
  });

  // Generates: GET, POST on /api/items and GET, PUT, DELETE on
  // /api/items/:id for the Items collection
  Api.addCollection(Policy);

Perhaps you should move your code to the server directory? I am on Meteor 1.3.4.

Mikkel
  • 7,693
  • 3
  • 17
  • 31