This package provides an HTTP client mixin for Moleculer microservices, enabling them to make requests to external REST APIs. It is currently at version 0.4.2 and wraps the popular `got` library for HTTP requests. While there's no explicit release cadence stated for this particular mixin, it generally follows the Moleculer ecosystem's development pace. Its key differentiators include seamless integration into Moleculer services via mixins, providing declarative HTTP actions (`get`, `post`, `put`, `patch`), and centralized configuration for logging, error handling, and `got` options within the service settings. This approach simplifies HTTP communication within a microservice architecture, abstracting common concerns like request/response logging and error formatting directly into the service lifecycle.
npm install moleculer-http-clientVerified import paths — ran on the pinned version, not inferred.
Demonstrates creating a Moleculer service using the `moleculer-http-client` mixin, configuring its HTTP client settings, and then using the mixin's `get` and `post` actions to communicate with an external REST API, including basic error handling.
Ensure `url` and `opt` are correctly placed in `ctx.meta` for streaming actions: `await ctx.call('service.post', streamPayload, { meta: { url: 'https://api.example.com', opt: { headers: {...} } } });`Review the changelog for `got` when upgrading it directly or if `moleculer-http-client` updates its `got` dependency. Test `moleculer-http-client` functionality thoroughly after such upgrades. Consider pinning the `got` version if strict stability is required, or ensure `moleculer-http-client`'s `package.json` specifies compatible `got` ranges.
Always use `try...catch` blocks around `await ctx.call('service.action', ...)` for HTTP requests to gracefully handle errors. Additionally, configure Moleculer's `errorHandler` at the broker level for global error management.Verify that `mixins: [HttpClientMixin]` is present in your service definition. Ensure that the service name in `ctx.call` (e.g., `ctx.call('yourServiceName.get', ...)`) precisely matches the `name` property of your service.Double-check the URL for typos, verify that the target API is accessible (e.g., ping the host) from your Moleculer service's environment, and ensure no firewalls or network configurations are blocking the outbound connection.
Ensure your service definition includes a `settings` block with a properly structured `httpClient` object, for example: `settings: { httpClient: { logging: true, defaultOptions: {} } }`. All keys within `httpClient` should be correctly spelled.