Rest Api in Meteor

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

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

1 Like

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!!!

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

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

2 Likes

thank you so much bro.

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

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.

1 Like