Best Alternative for Handling REST API Endpoints When Migrating from Iron Router

Hi everyone,

I’m currently working on migrating a Meteor server-side app that primarily serves REST API calls. The app includes a single sign-in page but mainly functions as an API server, exposing OpenAPI endpoints.

Previously, we used Iron Router for both routing the sign-in page and handling the API endpoints. However, we are now migrating to Flow Router Extra for the sign-in functionality. Since Flow Router is client-side only, we need an alternative for handling server-side REST API endpoints.

I’ve seen that the official Meteor documentation suggests using WebApp from Meteor itself for handling HTTP requests. Would this be the best approach for implementing our API routes, or is there a better package recommended for this use case?

Any insights or recommendations would be greatly appreciated!

Thanks in advance!

Hello,
I have migrated from iron router to flow router.
For rest api end point I use the core package webapp :

import { WebApp } from 'meteor/webapp';
WebApp.connectHandlers.use('/api/v1/status', async (req, res, next) => {
  res.setHeader( 'Access-Control-Allow-Origin', '*' );
  res.setHeader( 'Content-Type', 'application/json' );
  let ok = 0; // 0 means not ok
  try {
    res.statusCode = 200;
    const c = await Meteor.users.find({}).countAsync();
    if (c > 0) ok = 1;
    res.end(JSON.stringify({ok}));
  } catch (e) {
    console.error(e);
    res.statusCode = 500;
    res.end(JSON.stringify({ok}));
  }
});

I use WebApp too. I think the more we stick to the core, the more stable our system is.

1 Like