moleculerjs / moleculer-http-client Goto Github PK
View Code? Open in Web Editor NEWHTTP client mixin that allows Moleculer services to communicate with remote REST APIs
License: MIT License
HTTP client mixin that allows Moleculer services to communicate with remote REST APIs
License: MIT License
got
, HTTP client that this mixin uses, was recently updated to v11 (release notes are here: https://github.com/sindresorhus/got/releases/tag/v11.0.0). This release has several breaking changes that need to be addressed in order to update the moleculer-http-client
.
ToDo list:
I am using the Moleculer project template. I have install moleculer-http-client. And I have added the httpClient to the setting. But I got the error "ServiceNotFoundError: Service 'http.get' is not found."
const HTTPClientService = require("moleculer-http-client");
module.exports = {
name: "greeter",
mixins: [HTTPClientService],
settings: {
// HTTP client settings
httpClient: {
// Boolean value indicating whether request should be logged or not
logging: true,
// // Log request function
// logOutgoingRequest: logOutgoingRequest,
// // Log response function
// logIncomingResponse: logIncomingResponse,
// Format the Response
responseFormatter: "body", // one of "body", "headers", "status", "raw"
// Format the Errors
// errorFormatter: errorFormatter,
// Got Client options
defaultOptions: {
// Put here any Got available option that can be used to extend Got client
}
}
},
/**
* Dependencies
*/
dependencies: [],
/**
* Actions
*/
actions: {
/**
* Say a 'Hello' action.
*
* @returns
*/
hello: {
rest: {
method: "GET",
path: "/hello"
},
async handler() {
this.broker.call('http.get', {
url: 'https://postman-echo.com/get?foo1=bar1&foo2=bar2'
});
return "Hello Moleculer";
}
},
},
};
`
Hi,
I need to get body and headers from response. So, I put:
httpClient: {
logging: true,
responseFormatter: "raw",
errorFormatter: httpError,
},
But, in this format is creating a circular reference, causing an error in json serializer:
"Converting circular structure to JSON --> starting at object with constructor 'TLSSocket' | property '_httpMessage' -> object with constructor 'ClientRequest' --- property 'socket' closes the circle"
"TypeError: Converting circular structure to JSON
--> starting at object with constructor 'TLSSocket'
| property '_httpMessage' -> object with constructor 'ClientRequest'
--- property 'socket' closes the circle
at JSON.stringify ()
at JSONSerializer.serialize (.../add-tools-http-api/node_modules/moleculer/src/serializers/json.js:35:27)
at RedisTransporter.serialize (.../add-tools-http-api/node_modules/moleculer/src/transporters/base.js:347:33)
at RedisTransporter.publish (.../add-tools-http-api/node_modules/moleculer/src/transporters/base.js:190:21)
at RedisTransporter.prepublish (.../add-tools-http-api/node_modules/moleculer/src/transporters/base.js:333:15)
at Transit.publish (.../add-tools-http-api/node_modules/moleculer/src/transit.js:1372:18)
at Transit.sendResponse (.../add-tools-http-api/node_modules/moleculer/src/transit.js:1166:15)
at .../add-tools-http-api/node_modules/moleculer/src/transit.js:507:23
at processTicksAndRejections (node:internal/process/task_queues:96:5)"
Thanks for any help
Create index.d.ts
file with the types
got
, HTTP client that this mixin uses, was recently updated to v12 (release notes are here: https://github.com/sindresorhus/got/releases/tag/v12.0.0). This release has several breaking changes that need to be addressed in order to update the moleculer-http-client
.
ToDo list:
const HTTPClientService = require("moleculer-http-client");
mixins: [HTTPClientService],
// this line throws an error in consolenpm run dev
--
Result :
Request error! TypeError : Converting circular structure to JSON
--> starting at object with constructor 'ServiceBroker'
| property 'services' -> object with constructor 'Array'
| index 0 -> object with constructor 'Service'
--- property 'broker' closes the circle
TypeError: Converting circular structure to JSON
--> starting at object with constructor 'ServiceBroker'
| property 'services' -> object with constructor 'Array'
| index 0 -> object with constructor 'Service'
--- property 'broker' closes the circle
at JSON.stringify (<anonymous>)
at Service.encodeResponse (/Volumes/Boskysoft/work-hdd/recrutiment-smart/play/nodejs/moleculer-js/http-client/node_modules/moleculer-web/src/index.js:649:16)
at Service.sendResponse (/Volumes/Boskysoft/work-hdd/recrutiment-smart/play/nodejs/moleculer-js/http-client/node_modules/moleculer-web/src/index.js:749:18)
at Service.callAction (/Volumes/Boskysoft/work-hdd/recrutiment-smart/play/nodejs/moleculer-js/http-client/node_modules/moleculer-web/src/index.js:625:10)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async /Volumes/Boskysoft/work-hdd/recrutiment-smart/play/nodejs/moleculer-js/http-client/node_modules/moleculer-web/src/index.js:460:21
/API: <= 500 GET /api/~node/services?withActions=true [+15.368 ms]
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.