Skip to content

Instantly share code, notes, and snippets.

@rikyperdana
Created July 13, 2017 18:31
Show Gist options
  • Save rikyperdana/a863535a8905370de42abc91b8f0ead0 to your computer and use it in GitHub Desktop.
Save rikyperdana/a863535a8905370de42abc91b8f0ead0 to your computer and use it in GitHub Desktop.
Meteor Restivus Tutorial
# Do it in bash
meteor create --bare rest; cd rest; meteor npm install; meteor
meteor add coffeescript nimble:restivus
# Write these in both.coffee
@Items = new Mongo.Collection 'items'
# Write these in server.coffee
if Meteor.isServer
Api = new Restivus
useDefaultPath = true
prettyJson: true
Api.addCollection Items,
routeOptions:
authRequired: true
# Add it on server.coffee then delete it
Accounts.createUser
username: 'myname'
password: 'mypassword'
# To login
curl http://localhost:3000/api/login -d 'username=myname' -d 'password=mypassword'
// status: 'sucess', data: authToken: 'yourtoken', userId: 'youruserid'
# To get all items
curl -X GET http://localhost:3000/api/items -H 'X-Auth-Token:yourtoken' -H 'X-User-Id:youruserid'
# To post an item
curl -X POST http://localhost:3000/api/items -d 'title=your title' -d 'text=your content' -H 'X-Auth-Token:yourtoken' -H 'X-User-Id:youruserid'
# To update an item
curl -X PUT http://localhost:3000/api/items/itemid -d 'title=your title' -d 'text=your content' -H 'X-Auth-Token:yourtoken' -H 'X-User-Id:youruserid'
# To delete an item
curl -X DELETE http://localhost:3000/api/items/itemid -H 'X-Auth-Token:yourtoken' -H 'X-User-Id:youruserid'
@manuelgrdz14
Copy link

tutorial is incorrect, line 12 should be like this (I had a lot of issues because of this error):
useDefaultAuth: true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment