Skip to content

Getting started

Terminal window
pnpm add grabkit
# npm install grabkit
# yarn add grabkit

Grabkit ships ESM, CJS, and TypeScript declarations. It runs in Node and in bundler-driven browser apps (no separate CDN bundle).

import grabkit from 'grabkit';
const grab = grabkit('https://api.example.com');

The factory returns a function you call with an endpoint string: uppercase HTTP method, a space, then the path.

const [data, error, meta] = await grab('GET /users/1');

Paths starting with / are resolved against baseURL. Absolute http:// or https:// URLs ignore baseURL.

Every grab resolves to a tuple [data, error, meta]:

if (error) {
// Grab failed: HTTP error or transport failure
return;
}
// Success: data is set, error is null
console.log(data, meta.statusCode);

Ordinary HTTP and transport failures are returned, not thrown. The only synchronous throw is GrabkitValidationError (for example a JSON:API write body missing type).

For data layers that expect thrown errors, use orThrow to get [data, meta] instead of the three-slot tuple.