Official Rest API support in Meteor?


#23

@kahmali, I’ve built a super duper simple JSON API package here: https://github.com/stubailo/meteor-rest/tree/master/packages/json-routes

I filed an issue on Restivus to remove the iron:router dep: https://github.com/kahmali/meteor-restivus/issues/38

Let me know if you are interested and have time to work together on integrating these to remove the dependency of Restivus on I:R. It should be minimal work, I just need two things:

  1. What is the return value that Iron Router expects in server side routes? I can’t find it in the documentation, and would like to replicate it in my package.
  2. Would you accept a PR replacing I:R with my package in Restivus?

#24

Hello everyone! I’ve spent my week experimenting and trying to push forward the state of REST APIs in Meteor, and I’ve come up with a preview release of a package:

simple:rest - The easiest way to add a REST API to your Meteor app.

Let me know what you think! It’s a preview, I’m open to changing anything that doesn’t seem right.

It’s not meant to solve every aspect of REST APIs for Meteor, just make a simple default that works for a wide variety of cases. I’ve also been working with @kahmali to improve Restivus, and will continue in the future.


#25

This is perfect ! I’m gonna try it thanks ! :slight_smile:


#26

great discussion. I have just been working with restivus and I really like it. I put together a very simple demo to help anyone get started with it (It’s based on the quickstart from restivus, but doesn’t use authentication and is a bit simpler)

as for one comment about why you might use REST as part of a meteor app, here’s a use-case: Say you are writing a meteor app and it needs to process incoming email messages… and you are using mailgun.com which provides hooks where they will POST to your REST endpoint the contents (json formatted) of any incoming mail message to their servers. In this case, without REST support in meteor, one would have to have a separate server running PHP/Apache or something like that which would accept the post from mailgun and insert it into some mongo database that your meteor app was also connected to. Possible, but much more bother than just enabling a REST endpoint in the main meteor app.


#27

Don’t mean to bring up a dead post but I felt it was important to leave an update here since this page is one of the top hits when doing a google search of meteor + rest.

There’s a meteor supported alternative to these dead packages. It’s in the meteor-base package and is called webapp



#28

Here’s a lib that might be helpful to some:

And here’s an example app showing how to use it:

Also, here’s a meteor feature request I put in on this topic, and the feedback:

And here’s another thread on it:


#29

your example (meteorpedia) doesn’t work anymore


#30

Indeed, I ran into a few issues with the lib and decided instead of reinventing the wheel, I’d just use Express.js + Meteor + Accounts. It’s worked out well so far, and I recommend this approach over any other for Web API solutions.

The work I did with JsonRoute helped me understand middleware and absolutely helped me build the custom Accounts token system into my Express.js + Meteor solution, so in the end it wasn’t time wasted.


#31

Ha! I’ve been looking through all these threads and options about creating a web API… I’m thinking I should just go Express, and seems like this gives me the final push. Are there any exceptional Express + Meteor resources that you used to get into it?

Thanks for doing that exploratory work for us :stuck_out_tongue:


#32

This got me started: http://www.mhurwi.com/meteor-with-express/, and with the Express API docs (which are very good), should be all you need (depending on your Accounts requirements that is).

:joy:


#33

FWIW I’ve been using the simple suite of REST packages and it’s been really easy. I didn’t want the full exposure of everything (all collections, publications, methods) over REST that simple:rest gives you so I’m just using simple:json-routes , simple:rest-json-error-handler, and simple:rest-accounts-password


#34

@efrancis, yeah, I did that at first, but decided to instead use Express – super easy to use with Meteor. :smile:


#35

Thanks @simonvuong , I was just reading this article looking for this kind of info.

Are there any downsides to this ? I mean, can we make a complete API with auth?

Thanks in advance.


#36

I think it depends by a “complete” api. Now didn’t dig into the docs or the source code… but first IMPRESSIONS tell me that webapp is meant for simple apis. I don’t think it comes with all the fancy features that express includes.

That being said, if you are using meteor, you shouldn’t need to build a “complete” api. If you did, you should pick a different stack imo. Meteor is best for “isolated” apps that work within it’s own ecosystem because it is so opinionated. If you’re looking to build a more reactive api, id suggest looking into mdg’ s Apollo stack.


#37

@simonvuong I ended up just using Meteor + Express and it works great. This is the recommended approach.


How to do the rest api integration test base on express in meteor
#38

Do you have some information or tutorials that you can share? Maybe some code?

I would like to know if I can make a complete api (with auth) using meteor and express together. And also, does it work with Meteor Galaxy?

Thanks.


#39

@aadams

Hello,how do you do the rest api integrate test base on express in meteor?

I have tried meteor test --full-app --driver-package meteortesting:mocha it did not work.
https://github.com/imhazige/benchmark-test-java-php-nodejs/blob/master/nodejs/meteor/test/t1-test.js also I have used normal mocha style by using meteor test mocha, but it throw error ‘mocha is not a command’,
it does working when in a normal express project
https://github.com/imhazige/benchmark-test-java-php-nodejs/tree/master/nodejs/express/test


#40

Sure I could write one up… DM me for details.


#41

DIdn’t build any tests for it so I can’t speak to it. Sorry.