Registry / devops / simple-http-rest-client

simple-http-rest-client

JSON →
library2.3.0jsnpmunverified

A lightweight framework for creating reliable REST HTTP clients in TypeScript and JavaScript. Current stable version is 2.3.0. It implements the Simple HTTP Request Builder pattern with the native fetch API, providing a clean, type-safe way to consume REST APIs. Key differentiators include seamless integration with the Plume Framework and Create Plume React Project, built-in support for JSON bodies and error handling, and a minimal dependency footprint. The library is designed for request/response APIs and explicitly avoids websockets or GraphQL.

npm install simple-http-rest-client
INSTALL
IMPORT
SIG · SIMPLE-HTTP-REST-C
S
simple-http-rest-client
devopsjavascriptv2.3.0
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.

createHttpFetchRequest
import { createHttpFetchRequest } from 'simple-http-rest-client'
import createHttpFetchRequest from 'simple-http-rest-client'
This is a named export, not a default one. Using default import will cause a runtime error.
HttpMethod
import { HttpMethod } from 'simple-http-rest-client'
const HttpMethod = require('simple-http-rest-client').HttpMethod
Works in both ESM and CJS, but ESM is preferred. CJS require works but may not be tree-shakeable.
HttpPromise
import { HttpPromise } from 'simple-http-rest-client'
Type export for promises returned by the HTTP client. Use for typing responses.
HttpError
import { HttpError } from 'simple-http-rest-client'
import { HttpError } from 'simple-http-request-builder'
HttpError is exported from this package, not from simple-http-request-builder. Common mistake to import from wrong package.

Shows how to configure a simple GET request using createHttpFetchRequest with fetch options and execute it.

import { createHttpFetchRequest, HttpMethod, HttpPromise, HttpError } from 'simple-http-rest-client'; const baseUrl = process.env.API_BASE_URL ?? 'http://localhost:3000'; const restRequest = <T>(method: HttpMethod, path: string): HttpPromise<T> => { return createHttpFetchRequest<T>( baseUrl, method, path, { headers: { 'Content-Type': 'application/json' }, mode: 'cors', } ).execute(); }; restRequest<{ message: string }>(HttpMethod.GET, '/hello') .then(res => console.log(res)) .catch((err: HttpError) => console.error(err.message));
Debug
Known issues
gotchacreateHttpFetchRequest returns a fetch request builder, not the executed promise. You must call .execute() to actually make the HTTP request.
fix
Ensure to chain .execute() at the end of the request builder chain.
affects: >=2.0
gotchaThe baseUrl must include the protocol (e.g., 'https://'). If omitted, fetch may fail or use current origin.
fix
Always include the protocol in baseUrl, e.g., 'http://localhost:3000/api'.
affects: >=2.0
deprecatedThe library previously had a default export for client creation in v1.x. This has been removed in v2.0.
fix
Use named export createHttpFetchRequest instead.
affects: >=2.0
gotchaHttpError.errorCode is a string, not a number. Developers may expect numeric HTTP status codes.
fix
Compare errorCode with string values or use HttpError.status for numeric status code.
affects: >=2.0
Errors
Common errors & fixes
TypeError: client.restRequest is not a function
Using an older v1.x style of creating a client object.
fix
Use createHttpFetchRequest directly instead of instantiating a client class.
Uncaught (in promise) TypeError: Failed to execute 'fetch' on 'Window': Invalid URL
baseUrl or path is malformed (e.g., missing protocol or leading slash).
fix
Ensure baseUrl includes protocol and path starts with '/'. Example: baseUrl = 'http://localhost:3000', path = '/users'.
Upgrade
Version history
2.3.0latest on npm
Audit
Dependencies
simple-http-request-builderrequiredCore dependency for building HTTP requests
Agent activity
5 hits · last 30 days
node
4
Amazon
1
Resources
simple-http-rest-client — npm install simple-http-rest-client · libregistry