Ankush Rishi February 2016

How to define API keys in restFul meteor?

I am new to rest api in meteorjs. I am trying to run the example explained in The meteor chef but getting this error:

ReferenceError: APIKeys is not defined
    at Object.API.authentication (api/config/api.js:4:19)
    at Object.API.connection (api/config/api.js:16:34)
    at Object.API.handleRequest (api/config/api.js:28:26)
    at [object Object].Router.route.where (api/pizza.js:9:9)
    at boundNext (packages/iron_middleware-stack/lib/middleware_stack.js:251:1)
    at runWithEnvironment (packages/meteor/dynamics_nodejs.js:110:1)
    at packages/meteor/dynamics_nodejs.js:123:1
    at [object Object].urlencodedParser (/Users/mac/.meteor/packages/iron_router/.1.0.12.13720an++os+web.browser+web.cordova/npm/node_modules/body-parser/lib/types/urlencoded.js:84:40)
    at packages/iron_router/lib/router.js:277:1
    at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)

The code is same as explained in the example

Answers


MatiK February 2016

It is because you didn't created APIKeys mongo collection as shown here: https://github.com/themeteorchef/writing-an-api/blob/master/code/collections/api-keys.js

Add this file to your project and then it'll work.

Here is explanation from post you linked:

Next, we try to insert a new key for our user into the APIKeys collection. Wait a minute! Where did this come from?! This collection was setup beforehand, but let’s talk about why we have a separate collection to begin with. The reason we want to separate our API key storage from the more predictable location of our user’s profile (the writable portion of a user’s record in the Meteor.users() collection) is that by default, the profile object is writable.

So you just missed this part of tutorial where they created APIKeys collection.

Post Status

Asked in February 2016
Viewed 2,775 times
Voted 6
Answered 1 times

Search




Leave an answer