Moleculer API Gateway

0.11.0 · active · verified Sun Apr 19

moleculer-web is the official API Gateway service for the Moleculer microservices framework. It enables publishing Moleculer services via HTTP/HTTPS, handling routing, middleware, authentication, authorization, and static file serving. Key features include multiple routing strategies (aliases, named parameters, REST shorthand), support for file uploads, CORS, ETag generation, HTTP/2, and rate limiting. It supports various body parsers (JSON, URL-encoded) and can act as a middleware in existing ExpressJS applications. The current stable version is 0.11.0, released recently. The project appears actively maintained with frequent updates, including breaking changes in major versions for Node.js compatibility and dependency updates, indicating a steady, albeit evolving, release cadence.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to instantiate a Moleculer ServiceBroker and integrate the moleculer-web API Gateway to expose a simple service via HTTP, providing immediate access to actions and system endpoints.

import { ServiceBroker } from 'moleculer';
import ApiService from 'moleculer-web';

const broker = new ServiceBroker({ logger: console });

// Create a dummy service to expose via the API Gateway
broker.createService({
    name: 'test',
    actions: {
        hello(): string {
            return 'Hello API Gateway!';
        }
    }
});

// Load the API Gateway service
broker.createService(ApiService);

// Start the broker and API Gateway
broker.start()
    .then(() => {
        console.log('Moleculer API Gateway started on http://localhost:3000');
        console.log('Test URLs:');
        console.log('- Call "test.hello" action: http://localhost:3000/test/hello');
        console.log('- Get node health info: http://localhost:3000/~node/health');
    })
    .catch(err => {
        console.error('Error starting Moleculer broker or API Gateway:', err);
    });

view raw JSON →