Registry / devops / detritus-rest

detritus-rest

JSON →
library0.8.0jsnpmunverified

A lightweight REST library for JavaScript and TypeScript, version 0.8.0, with TypeScript declarations included. Designed for simplicity and browser/Node compatibility, it provides a minimalistic API for common HTTP methods (GET, POST, PUT, DELETE, PATCH) and supports custom headers, query parameters, request bodies, and response parsing. Unlike heavier solutions like Axios, Detritus REST focuses on zero dependencies and a small footprint (under 5KB). It has a monthly release cadence with occasional breaking changes in minor versions, so pinning is recommended. Primarily used in Discord bot development (part of the Detritus ecosystem) but suitable for any REST API consumption.

npm install detritus-rest
INSTALL
IMPORT
SIG · DETRITUS-REST
D
detritus-rest
devopsjavascriptv0.8.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.

RestClient
import { RestClient } from 'detritus-rest'
const RestClient = require('detritus-rest')
ESM-only; CJS require throws. TypeScript types included.
RestRequestOptions
import type { RestRequestOptions } from 'detritus-rest'
import { RestRequestOptions } from 'detritus-rest'
Type import to avoid runtime overhead. Only usable as type.
default (RestClient)
import RestClient from 'detritus-rest'
import { default as RestClient } from 'detritus-rest'
Default export is RestClient; named import also works.

Shows how to import RestClient, make a GET request with an auth header, and handle the response.

import { RestClient } from 'detritus-rest'; const client = new RestClient(); async function fetchData() { try { const response = await client.get('https://api.example.com/data', { headers: { 'Authorization': `Bearer ${process.env.API_KEY ?? ''}` }, }); console.log('Data:', response.data); } catch (error) { console.error('Error:', error); } } fetchData();
Debug
Known issues
breakingRestClient constructor options changed in v0.7.0: baseUrl replaced with baseURL (capitalization)
fix
Use baseURL (camelCase) instead of baseUrl. Example: new RestClient({ baseURL: 'https://api.example.com' })
affects: >=0.7.0
deprecatedfetch() method deprecated in v0.6.0 in favor of explicit get/post/put/delete/patch methods
fix
Replace client.fetch('GET', url) with client.get(url) or the appropriate method.
affects: >=0.6.0
gotchaResponse data is always parsed as JSON; non-JSON responses will throw. Use `response.raw` to get raw text.
fix
For non-JSON responses, access response.raw or set { responseType: 'text' } in request options.
affects: >=0.5.0
gotchaTimeout handling: The package does not set a default timeout; requests may hang indefinitely.
fix
Pass a timeout option in milliseconds: client.get(url, { timeout: 5000 })
affects: >=0.0.0
breakingRemoved support for Node.js <14 in v0.8.0
fix
Upgrade Node.js to version 14 or higher.
affects: >=0.8.0
Errors
Common errors & fixes
Error: Cannot find module 'detritus-rest'
Package not installed or import path incorrect.
fix
Run 'npm install detritus-rest' and ensure your import uses 'detritus-rest' not 'detritus-rest/lib'.
TypeError: client.get is not a function
Using CommonJS require instead of ESM import; the default export is an object with methods, but CJS returns a function.
fix
Use 'import { RestClient } from "detritus-rest"' in an ESM context or switch to dynamic import().
SyntaxError: Unexpected token < in JSON at position 0
Server returned HTML (e.g., error page) but the library tried to parse as JSON.
fix
Check the URL and response status; use response.raw to see the actual response text.
TypeError: Cannot read properties of undefined (reading 'data')
The response object might be undefined due to a network error or missing 'await'.
fix
Ensure you await the request: const response = await client.get(url); and handle errors with try/catch.
Upgrade
Version history
0.8.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources