Registry / devops / ut-port-http

ut-port-http

JSON →
library8.9.9jsnpmunverified

HTTP/HTTPS client port module for the UT framework, built on top of the 'request' library. Current stable version is 8.9.9. It provides a configurable HTTP client for making web service requests with features like TLS support, response parsing (JSON/XML), timeouts, custom headers, and message transformation via send/receive hooks. Part of the UT ecosystem, it integrates tightly with UT's bus architecture. Compared to using 'request' or 'axios' directly, it offers a structured configuration format and automatic error handling tailored for microservice communication. Release cadence is irregular, tied to UT framework updates.

npm install ut-port-http
INSTALL
IMPORT
SIG · UT-PORT-HTTP
U
ut-port-http
devopsjavascriptv8.9.9
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

portHttp
const portHttp = require('ut-port-http');
import portHttp from 'ut-port-http';
This is a CommonJS module; default export is a function that creates a port instance. ESM import may not work without a bundler.
config
const httpPort = require('ut-port-http')({ id: 'myPort', url: 'http://example.com', uri: '/api', method: 'post' });
const httpPort = require('ut-port-http').create({ url: 'http://example.com' });
The module exports a factory function directly, not a class or create method.
send
module.exports = { id: 'myPort', type: 'http', url: 'http://example.com', send: function(msg) { return msg; } }
module.exports = { send: (msg) => msg }
The module expects a config object exported from a .js file; send/receive are methods on that config. Arrow functions are fine in modern Node.

Shows a basic HTTP port configuration using ut-port-http, with common options like URL, method, and transforming the response.

// example-config.js const portHttp = require('ut-port-http'); module.exports = { id: 'myHttpPort', type: 'http', logLevel: 'debug', url: 'http://jsonplaceholder.typicode.com', uri: '/posts/1', method: 'get', receive: function(msg) { if (msg.$$ && msg.$$.mtid === 'error') return msg; msg.payload = JSON.parse(msg.payload); return msg; }, send: function(msg) { return msg; }, start: function() { console.log('HTTP port started'); } };
Debug
Known issues
deprecatedThe underlying 'request' module is deprecated as of 2020. ut-port-http depends on it, which may lead to security and compatibility issues.
fix
Consider migrating to a port that uses 'node-fetch' or 'axios' if possible, or pin to a supported version of 'request'.
affects: >=8.0.0
gotchaThe receive function must return the message object; if not, subsequent handlers may break.
fix
Always return msg from receive, even on error: if(msg.$$.mtid === 'error') return msg;
affects: >=8.0.0
gotchaThe configuration object must have 'type: http' explicitly; otherwise the port may not be recognized as HTTP.
fix
Include 'type': 'http' in the module.exports object.
affects: >=8.0.0
breakingIn version 8, the response format changed: previously 'body' now wrapped under 'payload' and 'httpStatus'. Legacy code expecting 'body' property will break.
fix
Update receive functions to read msg.payload and msg.httpStatus instead of msg.body.
affects: >=8.0.0
gotchaSetting 'parseResponse' to true but lacking a parser for the content type (e.g., XML) will throw an error.
fix
Ensure compatible parsers are installed (e.g., xml2js) or set parseResponse to false and handle parsing manually.
affects: >=8.0.0
Errors
Common errors & fixes
Error: Cannot find module 'request'
Missing dependency: 'request' is a peer dependency that must be installed separately.
fix
Run: npm install request
TypeError: this.bus.importMethod is not a function
The 'start' function expects the port to be registered in a UT bus; standalone use fails.
fix
Ensure the port is used within a UT application context (e.g., ut-run).
TypeError: Cannot read property 'mtid' of undefined
The receive function accesses msg.$$.mtid but msg.$$ is undefined when response is not an error.
fix
Check for msg.$$ existence: if(msg.$$ && msg.$$.mtid === 'error') return msg;
Upgrade
Version history
8.9.9latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
ut-port-http — npm install ut-port-http · libregistry