Using Meteor as a classic backend

Hello everyone,

I’m wondering if Meteor can be used as a classic backend for a Rest API and websockets.

I found Restivus which is spectacular, I can turn Meteor into a full Rest API with security and everything. But how to use sockets now ? It is the only part that I can’t found.

I found this approach interesting so I can build a backend for already existing front ends (angular/ember) and also for DDP clients.

This way I don’t have to build two different backends based on different frameworks (express for classic Rest API and Meteor for DDP).
Thanks.

2 Likes

You can just code everything as you would normally, then configure Restivus on top as all it does it create server side routes.

This might be interesting for you: https://github.com/mondora/asteroid

1 Like

This doesn’t directly answer your questions but it may be a helpful pattern to use for model logic that shared across Rest and DDP methods with no duplication. I’ve used it in a few prod. apps that needed to share across meteor apps and rest api

Asteroid looks very interesting, thanks benjick !
@SkinnyGeek1010 : This is effectively a good design practice, thanks.
@hellstad : Yes I know that, the http part is solved, the only part missing is how to use classic websockets.

Let’s say I have this angular client code :

 io.socket.get('/pets/all', function (data) {
    $scope.pets = data;

    // Re-render the DOM
    $scope.$apply();
  });

  // Listen for changes to pets
  io.socket.on('pet', function (socketEvent){
    console.log('Something happened with a pet.');
    console.log(socketEvent);


    // Find the pet who barked and update that in the UI.
    _.each($scope.pets, function ($pet){

      // I'm casting these ids to integers
      // (if I was using string primary key values, like in mongo, I wouldn't)
      if (+$pet.id === +socketEvent.id) {
        $pet.hasBarked = true;
      }
    });

    // Re-render the DOM
    $scope.$apply();
  });

How can I publish my pet collection but using classic websocket and not DDP ?
Or how can I use simple websocket like socket.io ?

Asteroid is indeed pretty cool, I’ve also used it before. I’ve used a pure Polymer frontend, since I prefer the component model of Polymer to Blaze templates.

But then I found myself a bit isolated from the packages on Atmosphere. Not wanting to implement a lot of logic that already existed as Atmosphere packages, I changed to Meteor. To stay as backend agnostic as possible, I put all my Polymer code simply in the public/ folder and used the public APIs exposed by Meteor to the client. But then again for using custom build tools for Polymer I need to write integrations into the Meteor world and I actually wish I would have stayed with Asteroid.

But why do I need to be in this situation anyway? According to the Meteor website the Meteor platform is just a recommended stack, consisting of all the core parts of Meteor. Why isn’t it possible to just use the DDP implementation and mini-mongo on a client app? As I read on the website this should be possible sometime. In the Trello roadmap I can not find something about this.

Does somebody know if there is an interest of the Meteor team to go into that direction or will it always be that other libraries/frameworks/tools have to integrate into Meteor and not the other way round?

2 Likes

I made Fetcher for goals similar to yours. The idea is to use Method’s to retrieve data to the client, and Fetcher helps you re-use it everywhere:

1 Like

@msavin very cool!

I made something very similar for Blonk’s ‘feed’ because an edge case would make subscriptions glitch when swiping. Doing it this way gives you more granular control on when the data gets updated.

1 Like