Rest Api in Meteor


#1

hey, i have spend too much of time to do meteor with rest api.but i cant able to do that .i have used Collection api, Restivus .every time i am getting HTML tags as response


#2

Can you share code showing how you’re initializing restivus, adding your collection to it, and defining your restivus route?


#3

Items = new Mongo.Collection(‘items’);
Articles = new Mongo.Collection(‘articles’);

if (Meteor.isServer) {

// Global API configuration
var Api = new Restivus({
useDefaultAuth: true,
prettyJson: true
});

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

// Generates: POST on /api/users and GET, DELETE /api/users/:id for
// Meteor.users collection
Api.addCollection(Meteor.users, {
excludedEndpoints: [‘getAll’, ‘put’],
routeOptions: {
authRequired: true
},
endpoints: {
post: {
authRequired: false
},
delete: {
roleRequired: ‘admin’
}
}
});

// Maps to: /api/articles/:id
Api.addRoute(‘articles/:id’, {authRequired: true}, {
get: function () {
return Articles.findOne(this.urlParams.id);
},
delete: {
roleRequired: [‘author’, ‘admin’],
action: function () {
if (Articles.remove(this.urlParams.id)) {
return {status: ‘success’, data: {message: ‘Article removed’}};
}
return {
statusCode: 404,
body: {status: ‘fail’, message: ‘Article not found’}
};
}
}
});
}

above code only!!!


#5

hello,bro can you help me as soon as possible?


#6

I threw together a quick sample app using restivus and a collection of widgets here. This will show you how to set it up and use it with Meteor 1.3. Clone the app, start it, then run:

curl http://localhost:3200/api/widgets


#7

thank you so much bro.


#8

can you give me one example with get ,post ,put ??


#9

Brosef, Just reading the docs shows that unless you explicitly exclude endpoints, all http verbs are available (including post & put).

Does that make sense, Vincent Van Bro?

Also, there’s no security unless you specify it, Brotato Chip.

See Also.