Registry / http-networking / sn-http-request

sn-http-request

JSON →
library24.0.3jsnpmunverified

sn-http-request is a specialized JavaScript HTTP client designed specifically for interacting with ServiceNow instances. It aims to simplify common HTTP operations within the ServiceNow ecosystem by providing features such as automatic user token refresh, asynchronous request queuing, request cancellation, request/response interceptors, and efficient request batching (defaulting to batch requests within a 50ms window). The current stable version is 24.0.3, though its public release cadence might be slower as it's primarily intended for internal ServiceNow development. Its key differentiators compared to generic HTTP clients like Axios or the Fetch API include built-in XSRF token handling and request compression, making it optimized for ServiceNow's API landscape and reducing boilerplate for common tasks in that environment.

npm install sn-http-request
INSTALL
IMPORT
SIG · SN-HTTP-REQUEST
S
sn-http-request
http-networkingjavascriptv24.0.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

snHttpFactory
import { snHttpFactory } from 'sn-http-request';
const snHttpFactory = require('sn-http-request').snHttpFactory;
The library primarily uses named exports and a factory pattern for client instantiation. ESM is the preferred import style.
snHttpFactory (CJS)
const { snHttpFactory } = require('sn-http-request');
const snHttpFactory = require('sn-http-request'); // Would import the entire module, not the factory function directly
For CommonJS environments, destructuring the `require` call is the correct way to access the named export `snHttpFactory`.
SnHttpClientInstance
import type { SnHttpClientInstance } from 'sn-http-request';
When using TypeScript, import `SnHttpClientInstance` as a type for explicit client type declarations.

This quickstart demonstrates how to create an `sn-http-request` client instance, configure it with base URL, authentication, and interceptors, and then perform a GET request to fetch a ServiceNow incident. It also includes an example for creating a new incident via a POST request.

import { snHttpFactory } from 'sn-http-request'; const SN_INSTANCE_URL = process.env.SN_INSTANCE_URL ?? 'https://yourinstance.service-now.com'; const SN_USERNAME = process.env.SN_USERNAME ?? 'admin'; const SN_PASSWORD = process.env.SN_PASSWORD ?? 'password'; const snHttp = snHttpFactory({ baseURL: SN_INSTANCE_URL + '/api/now/table/', auth: { username: SN_USERNAME, password: SN_PASSWORD, }, // Max 2 concurrent requests by default, set to 5 for demonstration maxConcurrent: 5, // Disable batching for this client instance for immediate requests batching: false, // Example interceptor to log requests interceptors: { request: [ (config) => { console.log(`[Request Interceptor] Making ${config.method?.toUpperCase()} request to ${config.url}`); return config; }, ], response: [ (response) => { console.log(`[Response Interceptor] Received ${response.status} from ${response.config.url}`); return response; }, ], }, }); async function fetchIncident(sysId: string) { try { console.log(` Fetching incident with sys_id: ${sysId}...`); const response = await snHttp.get(`incident/${sysId}`); console.log('Incident Data:', JSON.stringify(response.data, null, 2)); } catch (error: any) { console.error('Error fetching incident:', error.message || error); if (error.response) { console.error('Response status:', error.response.status); console.error('Response data:', error.response.data); } } } // Example: Replace with a valid incident sys_id from your ServiceNow instance fetchIncident('a_valid_incident_sys_id_here'); // Example: Creating a new incident (requires POST permissions and appropriate payload) async function createIncident() { try { console.log('\nCreating a new incident...'); const newIncidentData = { short_description: 'Test incident from sn-http-request client', impact: '3', urgency: '3', }; const response = await snHttp.post('incident', { data: newIncidentData }); console.log('New Incident Created:', JSON.stringify(response.data, null, 2)); } catch (error: any) { console.error('Error creating incident:', error.message || error); if (error.response) { console.error('Response status:', error.response.status); console.error('Response data:', error.response.data); } } } // Uncomment to run the create incident example // createIncident();
Debug
Known issues
gotchaThe `sn-http-request` library is primarily intended for internal ServiceNow development use. While publicly available, its release cadence and feature prioritization may differ from general-purpose HTTP clients, potentially leading to slower updates or fixes for external use cases.
fix
Review the npm page and GitHub repository regularly for updates and consider this context when planning long-term dependencies. For general JavaScript HTTP needs outside of a ServiceNow context, alternatives like Axios or the native Fetch API might be more suitable.
affects: >=1.0.0
breakingAs with any API client, changes to the underlying ServiceNow REST API (e.g., changes to endpoint paths, required parameters, response field names, or authentication methods) can cause breaking changes to applications using `sn-http-request`.
fix
Always consult ServiceNow API documentation for the specific API version you are targeting. Implement robust error handling and defensive programming (e.g., checking for property existence before access) to gracefully handle unexpected API changes. Keep `sn-http-request` updated to leverage any compatibility fixes.
affects: >=1.0.0
gotchaBy default, `sn-http-request` clients will batch HTTP requests made within a 50ms window. While beneficial for performance in some scenarios, this can lead to unexpected delays or behavior if immediate, unbatched requests are expected.
fix
To disable batching for a client instance, set `batching: false` in the `snHttpFactory` options. For individual requests, set `batch: false` within the request config (e.g., `snHttp.post('/users/1', { data: {fName: 'Fred'}, batch: false });`).
affects: >=1.0.0
Errors
Common errors & fixes
Error sending HTTP request
This error often indicates a timeout before the server sends a response, or an issue connecting to the remote service.
fix
Increase the `timeout` setting in your request configuration or `snHttpFactory` options. Verify network connectivity to the ServiceNow instance and check the instance's availability. Ensure the target API endpoint is correct and accessible. For server-side issues, check ServiceNow instance logs.
The HTTP request is unauthorized with client authentication scheme 'Digest'.
This specific error message (or similar 'unauthorized' errors like 401 or 403 Forbidden) typically means the provided credentials or authentication token are invalid or lack the necessary permissions for the requested operation.
fix
Verify that the `username` and `password` provided to `snHttpFactory` are correct for your ServiceNow instance and have the 'itil' role or other required permissions for the target API. Ensure any `xsrfToken` is correctly configured and still valid. Review ServiceNow security rules and API access policies.
HTTP status code 404: Not Found
The requested API endpoint or resource could not be found on the ServiceNow instance.
fix
Double-check the `baseURL` configured in `snHttpFactory` and the relative paths provided to `get`, `post`, etc. Ensure the ServiceNow API endpoint exists and is correctly spelled. Verify that the user account has access to the table or API being queried.
Upgrade
Version history
24.0.3latest on npm
Audit
Dependencies
fflaterequiredUsed for Gzip compression of request payloads when `httpRequestCompressionThreshold` is set.
Agent activity
16 hits · last 30 days
node
14
OpenAI (training)
1
Resources
sn-http-request — npm install sn-http-request · libregistry