Registry / http-networking / http-service

http-service

JSON →
library1.1.3jsnpmunverified

A simple Node.js module wrapping Node's native http/https module, targeting JSON data exchange between servers. Version 1.1.3 provides GET, POST, PUT, DELETE requests with both callback and Promise support. It allows base URL initialization and can be subclassed for custom service APIs. Limited documentation and low maintenance activity; no significant updates since 2018. Suitable for simple JSON-based server-to-server communication but lacks advanced features like interceptors, retries, or streaming support found in Axios or Got.

npm install http-service
INSTALL
IMPORT
SIG · HTTP-SERVICE
H
http-service
http-networkingjavascriptv1.1.3
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.

HttpService
const HttpService = require('http-service');
import HttpService from 'http-service';
Package is CJS only, no ESM exports. Use require() exclusively.
Constructor new HttpService(url)
const service = new HttpService('https://example.com');
HttpService.init('https://example.com');
init() is an instance method for later initialization, not a static method. The constructor accepts an optional URL string.
Instance methods (get, post, put, delete)
service.get('/path', {query: 1}, callback);
service.get('/path', {query: 1}).then();
If no callback is provided, the method returns a Promise. However, the Promise is not fully documented; prefer using callbacks.

Shows basic usage: creating an instance, initializing with a base URL, and performing GET, POST, and DELETE requests with callbacks and Promises.

const HttpService = require('http-service'); const service = new HttpService(); service.init(process.env.API_URL || 'http://localhost:3000'); // GET with callback service.get('/data', {limit: 10}, (err, data) => { if (err) console.error('Error:', err); else console.log('Data:', data); }); // POST with Promise (no callback) service.post('/data', {}, {name: 'test'}) .then(data => console.log('Created:', data)) .catch(err => console.error('Error:', err)); // DELETE service.delete('/data/1', {}, (err, result) => { if (err) console.error('Delete failed:', err); else console.log('Deleted:', result); });
Debug
Known issues
gotchaThe `init` method does not validate the URL or handle protocol errors gracefully; invalid URLs may cause unhandled exceptions.
fix
Always validate the URL before calling init, and use try-catch around instantiation.
affects: >=1.0.0
deprecatedCallbacks are the primary pattern but Promise support exists; mixing both in the same codebase can lead to confusion.
fix
Choose one pattern (prefer callbacks for consistency) and stick to it.
affects: >=1.1.0
gotchaThe library does not support HTTPS strict SSL by default; self-signed certificates may cause failures unless NODE_TLS_REJECT_UNAUTHORIZED is set.
fix
Set environment variable NODE_TLS_REJECT_UNAUTHORIZED=0 (not recommended for production) or use a custom agent.
affects: >=1.0.0
gotchaQuery parameters are passed as an object, but the library does not deeply serialize nested objects; only first-level keys are sent.
fix
Serialize nested query parameters manually using a library like qs or querystring.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'http-service'
Package not installed or not in node_modules.
fix
Run 'npm install http-service' in your project directory.
TypeError: service.get is not a function
Trying to call method on the class itself instead of an instance.
fix
Create an instance: const service = new HttpService(); then call service.get().
Error: getaddrinfo ENOTFOUND
Invalid or unreachable hostname passed to init.
fix
Ensure the URL is correct and the server is reachable. Use an IP or valid domain.
Upgrade
Version history
1.1.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
http-service — npm install http-service · libregistry