Scoped HTTP Client for Node.js

0.11.0 · abandoned · verified Tue Apr 21

Scoped HTTP Client provides a fluent, chainable API wrapper around Node.js's native `http` client, simplifying common HTTP request patterns. Instead of handling numerous optional arguments directly on `http.request`, it allows developers to build requests by chaining methods like `.header()`, `.path()`, `.query()`, and `.get()`/`.post()`. A key feature is its 'scoping' mechanism, enabling temporary modifications to client parameters for specific requests without altering the base client instance. The package's current stable version is 0.11.0, last published in 2015. Given its age and an `engines` declaration targeting `node >= 0.8.0`, it is no longer actively maintained and is likely incompatible with modern Node.js environments. Its approach to request building has largely been superseded by contemporary HTTP clients like Axios, Got, or the native Fetch API, which offer more robust features, Promises/async-await support, and active maintenance.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates creating a client, chaining methods for headers and paths, executing a GET request, and making a POST request within a scoped context, including basic error handling.

const scopedClient = require('scoped-http-client');
const util = require('util'); // Node.js built-in module

// Example 1: Basic GET request
const githubClient = scopedClient.create('https://api.github.com')
  .header('accept', 'application/json')
  .path('users/technoweenie')
  .get()(function(err, resp, body) {
    if (err) {
      console.error('Error fetching user:', err);
      return;
    }
    console.log('GET Response Status:', resp.statusCode);
    util.puts('User Info: ' + body);
  });

// Example 2: POST request within a scope
const token = process.env.GITHUB_TOKEN ?? 'YOUR_DUMMY_GITHUB_TOKEN'; // Replace with a real token or handle auth
const scopedBaseClient = scopedClient.create('https://api.github.com')
  .query({ token: token });

scopedBaseClient.scope('user/repos', function(cli) {
  const data = JSON.stringify({ name: 'my-new-repo', description: 'A test repository' });
  cli.post(data)(function(err, resp, body) {
    if (err) {
      console.error('Error creating repo:', err);
      return;
    }
    console.log('POST Response Status:', resp.statusCode);
    util.puts('Repo creation response: ' + body);
  });
});

view raw JSON →