Meteor webapp vs Picker vs simple:rest for REST API

Are there any advantages or issues in choosing one of these methods for implementing a REST API endpoint over the others? I was using Picker but decided to switch to Meteor’s built-in meteor/webapp just to reduce dependencies.

2 Likes

In my opinion:

  1. with webapp, you must manually parse url, request body, params to get suitable results,
  2. with Picker, I dont have any experiences
    I suggest that you should you webapp + express:
import express from 'express';

const app = express();
WebApp.connectHandlers.use(Meteor.bindEnvironment(app));
app.post('/', function (req, res) {
  res.send('POST request to the homepage')
})

Not sure what your timeframe is, but I’ll be evaluating the same thing over the next week or two. Been using picker for ~2 years but I’m in the middle of some refactoring and this is on my list. If I keep it or switch, I’ll try to post my reasons here.

Using webapp with incoming JSON data is super easy and doesn’t require any special steps:

WebApp.connectHandlers.use('/api/whatever', function (req, res) {
  req.on('data', Meteor.bindEnvironment(chunk => {
    const data = JSON.parse(chunk);
    // ... do stuff here
  }));

  res.writeHead(200);
  res.end('OK');
});
5 Likes

Hi @vigorwebsolutions so did you kept or switched ?

We started using WebApp.connectHandlers.use exclusively.

It’s very similar to express, basically you can intercept the routes you want to handle server side, or just call next() to pass the request to the next handler (flowRouter in our case).

1 Like

Has any help how to use WebApp?

1 Like

this is the WORST documentation i have ever seen. a page with two meaningless examples, there is NO help here for beginners ( yes i am a beginner at webapp, 40 years of programming exp.) it appears the expectation is that the user has already done this for say a year before they read the page here. sad

The docs are fine honestly, the webapp package just exposes other existing things that are already documented. See this excerpt from that linked webapp docs page:

webapp exposes the connect API for handling requests through WebApp.connectHandlers . Here’s an example that will let you handle a specific URL:

It links to the full documentation for connect and the API that is exposed using webapp.connectHandlers.

Below on the same webapp docs page you see this:

handler - this is a function that takes three arguments:

  • req - a Node.js IncomingMessage object with some extra properties. This argument can be used to get information about the incoming request.
  • res - a Node.js ServerResponse object. Use this to write data that should be sent in response to the request, and call res.end() when you are done.
  • next - a function. Calling this function will pass on the handling of this request to the next relevant handler.

Which again links to the full existing documentation for the request and response objects and all of the events, methods and properties that they expose. These are part of the standard node.js API and have plenty of existing resources available already.