Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestions: enable using publications and meteor methods #15

Closed
satyavh opened this issue Mar 7, 2015 · 3 comments
Closed

Suggestions: enable using publications and meteor methods #15

satyavh opened this issue Mar 7, 2015 · 3 comments

Comments

@satyavh
Copy link

satyavh commented Mar 7, 2015

Not sure if this is possible, but to have more DRY code it would be useful to be able to

  1. turn a Meteor Publication into an API.
    Because in a publication you already limit what you publish of a collection. There's a big chance your API exposure won't differ, but that means duplication of code in endpoint actions.

2. use meteor methods in endpoint actions
Because you already have your methods set up to do something with your collections. So if you could use those it means you don't have to duplicate code.

UPDATE: just figured out that is possible, with the exception that Meteor.userId() is not set. So if you protected your methods with check for userId the API can't run the method.

@kahmali
Copy link
Owner

kahmali commented Mar 9, 2015

Hey Satya,

  1. This is definitely something that needs to be added to Restivus. I'm sure you're already aware of the http-publish package that has this functionality. I have a few other things that are higher priorities for me (e.g., additional testing, route/endpoint versioning, and JSON PATCH support), but if someone wants to add it I will gladly work on hashing out an acceptable API with them or I will happily accept a pull request if someone would like to be extra ambitious. I just know that it's going to take a couple of weeks of work to design and implement a clean API that plays nicely with everything else, and I need those other features I named for my own API asap. I went ahead and added the feature to the roadmap, but it may be more than a month before I get around to implementing this.
  2. I've used Meteor methods in multiple endpoints, including authenticated endpoints. In my situation, I'm calling through to the method from within the endpoint. Are you talking about just applying the entire Meteor method as the endpoint function? That I haven't tried. If there is an easy way to add this to the API I will do it, but otherwise it will probably be fairly low priority since it's probably only saving a single line of code to call through to the method from within the endpoint (if I understand you correctly). Here's an example of what I do that works with authenticated endpoints:
Restivus.addRoute 'test', authRequired: true,
  get: ->
    Meteor.call('someMeteorMethod', @userId, arg2)

@stubailo
Copy link
Contributor

Working on a package that has this as its main feature here: https://github.com/stubailo/meteor-rest

Hoping to have a first version out on Tuesday, but until then here is a hackpad with design and discussion: https://meteor.hackpad.com/Meteor-Hack-Week-REST-APIs-with-Meteor-XK2NNXqhUvj

@kahmali
Copy link
Owner

kahmali commented May 13, 2015

@stubailo's simple:rest package (referenced above) is designed specifically for this, so I have no plans to provide any additional functionality for it in Restivus. I'm open to debate as always, but I'm going to go ahead and close this for now.

@kahmali kahmali closed this as completed May 13, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants