Reputation: 3425
I want to make a simple API using meteor to use.
So that a URL like www.myapp.com/artist/id returns a JSON response of some work I do on the server.
I am not sure the best way to do this using meteor (and perhaps backbone).
I know I will use Meteor.http.get("url") but not quite sure how I should define the routes for the api.
Or would it be best to make the api in a different environment and then just make calls to it?
Upvotes: 0
Views: 1181
Reputation: 8629
You can use https://atmosphere.meteor.com/package/collection-api to perform CRUD operations on Collections over a RESTful API
Upvotes: 2
Reputation: 873
At the moment, Meteor does not support server-side routing (Little/big bird telling me it is on the roadmap). Though with some hacky work around you can achieve it. Although if you want to keep clean code and stay away from the hacky stuff a external system might be the better choice here. BUT let's stay Meteor minded and 'hack'-away.
A server-side route can be achieved by using this code :
var connect = __meteor_bootstrap__.require("connect");
__meteor_bootstrap__.app
.use(connect.query())
.use(connect.bodyParser()) //I add this for file-uploading
.use(function (req, res, next) {
Fiber(function() {
if(req.method == "POST"){
if(req.url.indexOf('/upload') !== -1){
res.writeHead(200, {'Content-Type': 'application/json'});
res.write(JSON.stringify({"success" : true}));
res.end();
return;
}
}
next();
}).run();
});
Upvotes: 1
Reputation: 30565
You could use page.js to help you with routing. Meteor & Backbone.js have a few feature that are quite similar in Model/Collection & View/Template.
Upvotes: 0