Getting started
Install
Section titled “Install”pnpm add grabkit# npm install grabkit# yarn add grabkitGrabkit ships ESM, CJS, and TypeScript declarations. It runs in Node and in bundler-driven browser apps (no separate CDN bundle).
Create a grab callable
Section titled “Create a grab callable”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.
Narrow the result
Section titled “Narrow the result”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 nullconsole.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.
Next steps
Section titled “Next steps”- JSON:API (default): denormalised reads and write envelopes
- Plain JSON:
format: 'json'for non–JSON:API APIs - Configuration: casing, headers, per-call overrides
- Errors & results:
GrabkitError, transport errors, andmeta - TanStack Query, SWR: client cache libraries
- Node.js: route handlers and server-side grabs