I have searched around but cant find an a satisfactory answer to this question.
I have a meteor website where users login and create content. I also want to create a pho
I published a package for writing REST APIs in Meteor 0.9.0+ that supports authentication. It is meant to replace RestStop2 (the accepted answer) now that it is deprecated, and has a similar API:
https://github.com/krose72205/meteor-restivus
It was inspired by RestStop2 and built with Iron Router's server-side routing.
UPDATE: I just wanted to include a code example for anyone that finds this. This is the Restivus Quick Start example from the GitHub README:
Items = new Mongo.Collection 'items'
if Meteor.isServer
# API must be configured and built after startup!
Meteor.startup ->
# Global API configuration
Restivus.configure
useAuth: true
prettyJson: true
# Generates: GET, POST, DELETE on /api/items and GET, PUT, DELETE on
# /api/items/:id for Items collection
Restivus.addCollection Items
# Generates: GET, POST on /api/users and GET, DELETE /api/users/:id for
# Meteor.users collection
Restivus.addCollection Meteor.users,
excludedEndpoints: ['deleteAll', 'put']
routeOptions:
authRequired: true
endpoints:
post:
authRequired: false
delete:
roleRequired: 'admin'
# Maps to: /api/posts/:id
Restivus.addRoute 'posts/:id', authRequired: true,
get: ->
post = Posts.findOne @urlParams.id
if post
status: 'success', data: post
else
statusCode: 404
body: status: 'fail', message: 'Post not found'
post:
roleRequired: ['author', 'admin']
action: ->
post = Posts.findOne @urlParams.id
if post
status: "success", data: post
else
statusCode: 400
body: status: "fail", message: "Unable to add post"
delete:
roleRequired: 'admin'
action: ->
if Posts.remove @urlParams.id
status: "success", data: message: "Item removed"
else
statusCode: 404
body: status: "fail", message: "Item not found"