Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should I run a REST API with Meteor?

I need the Meteor server to handle a very simple POST request not coming from the application client. With Express, I'd just do something like app.post('/something', function....

Is there an equivalent in Meteor? If not, how should I set this up, startup an Express server in a is_server context?

like image 449
Hudon Avatar asked Apr 23 '12 14:04

Hudon


3 Answers

Meteor does not yet have the built in functionality to provide a restful API.

like image 135
greggreg Avatar answered Oct 04 '22 21:10

greggreg


You can build basic routing into our application using Backbone, as in the Meteor example provided here: http://meteor.com/examples/todos

You can do something like this:

var AppRouter = Backbone.Router.extend({
  routes: {
    "": "dashboard",
    "home": "dashboard",
    "profile": "profile",
},

profile: function () {
    Session.set("current_view", "profile")
    this.navigate('profile', {trigger: true});
},

Also take a look at: How to expose a RESTful Web Service using Meteor

like image 21
andreimpop Avatar answered Oct 04 '22 22:10

andreimpop


Alternatively you can serve RESTful APIs with Meteor using the meteor-collectionapi Atmosphere package. See also Is Meteor an option, if i need an additional REST API?.

like image 40
kynan Avatar answered Oct 04 '22 22:10

kynan