Lib

GRAB API Reference

Documentation / GRAB-URL

GrabMockHandler<TParams, TResponse>

Defined in: GRAB-URL.ts:654

Combined options and parameters interface Mock server configuration for testing

Type Parameters

TParams

any

TResponse

any

Properties

response

TResponse | (params: TParams) => TResponse

Mock response data or function that returns response

GRAB-URL.ts:656

method?

"GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS" | "HEAD"

HTTP method this mock should respond to

GRAB-URL.ts:658

params?

TParams

Request parameters this mock should match

GRAB-URL.ts:660

delay?

number

Delay in seconds before returning mock response

GRAB-URL.ts:662


GrabLogEntry

Defined in: GRAB-URL.ts:666

Request log entry for debugging and history

Properties

path

string

API path that was requested

GRAB-URL.ts:668

request

string

Stringified request parameters

GRAB-URL.ts:670

response?

any

Response data (only present for successful requests)

GRAB-URL.ts:672

error?

string

Error message (only present for failed requests)

GRAB-URL.ts:674

lastFetchTime

number

Timestamp when request was made

GRAB-URL.ts:676

controller?

AbortController

Abort controller for request cancellation

GRAB-URL.ts:678

currentPage?

number

Current page number for paginated requests

GRAB-URL.ts:680


GrabGlobal

Defined in: GRAB-URL.ts:684

Global grab configuration and state

Properties

defaults?

Partial<GrabOptions>

Default options applied to all requests

GRAB-URL.ts:686

log?

GrabLogEntry[]

Request history and debugging info

GRAB-URL.ts:688

mock?

Record<string, GrabMockHandler>

Mock server handlers for testing

GRAB-URL.ts:690

instance?

(defaultOptions?: Partial<GrabOptions>) => GrabFunction

Create a separate instance of grab with separate default options

GRAB-URL.ts:692


GrabFunction()

Defined in: GRAB-URL.ts:696

Main grab function signature with overloads for different use cases

Call Signature

GrabFunction<TResponse, TParams>(path: string): Promise<GrabResponse<TResponse>>;

Defined in: GRAB-URL.ts:705

Main grab function signature with overloads for different use cases

Type Parameters

TResponse

any

TParams

Record<string, any>

Parameters

path

string

Returns

Promise<GrabResponse<TResponse>>

The response object with resulting data or .error if error.

Author

vtempest (2025)

See

🎯 Examples 📑 Docs

Call Signature

GrabFunction<TResponse, TParams>(path: string, config: GrabOptions<TResponse, TParams>): Promise<GrabResponse<TResponse>>;

Defined in: GRAB-URL.ts:717

Main grab function signature with overloads for different use cases

Type Parameters

TResponse

any

TParams

Record<string, any>

Parameters

path

string

config

GrabOptions<TResponse, TParams>

Returns

Promise<GrabResponse<TResponse>>

The response object with resulting data or .error if error.

Author

vtempest (2025)

See

🎯 Examples 📑 Docs

Properties

defaults?

Partial<GrabOptions>

Default options applied to all requests

GRAB-URL.ts:723

log?

GrabLogEntry[]

Request history and debugging info for all requests

GRAB-URL.ts:726

mock?

Record<string, GrabMockHandler>

Mock server handlers for testing

GRAB-URL.ts:729

instance?

(defaultOptions?: Partial<GrabOptions>) => GrabFunction

Create a separate instance of grab with separate default options

GRAB-URL.ts:732


LogFunction()

Defined in: GRAB-URL.ts:736

Log function for debugging

LogFunction(message: string | object, options?: LogOptions): void;

Defined in: GRAB-URL.ts:741

Log function for debugging

Parameters

message

string | object

Message to log (string or object)

options?

LogOptions

Returns

void


printJSONStructureFunction()

Defined in: GRAB-URL.ts:745

Utility function to describe JSON structure

printJSONStructureFunction(obj: any): string;

Defined in: GRAB-URL.ts:751

Utility function to describe JSON structure

Parameters

obj

any

The JSON object to describe

Returns

string

String representation of object structure


GrabResponse<TResponse>

type GrabResponse<TResponse> = TResponse & object;

Defined in: GRAB-URL.ts:577

Core response object that gets populated with API response data

Type declaration

isLoading?

boolean

Indicates if request is currently in progress

GRAB-URL.ts:579

error?

string

Error message if request failed

GRAB-URL.ts:581

data?

TResponse | any

Binary or text response data (JSON is set to the root)

GRAB-URL.ts:583

Type Parameters

TResponse

any


GrabOptions<TResponse, TParams>

type GrabOptions<TResponse, TParams> = TParams & object;

Defined in: GRAB-URL.ts:588

Type declaration

headers?

Record<string, string>

include headers and authorization in the request

GRAB-URL.ts:590

response?

TResponse | (params: TParams) => TResponse | any

Pre-initialized object which becomes response JSON, no need for .data

GRAB-URL.ts:592

method?

"GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS" | "HEAD"

default="GET" The HTTP method to use

GRAB-URL.ts:594

cache?

boolean

default=false Whether to cache the request and from frontend cache

GRAB-URL.ts:596

cacheForTime?

number

default=60 Seconds to consider data stale and invalidate cache

GRAB-URL.ts:598

timeout?

number

default=30 The timeout for the request in seconds

GRAB-URL.ts:600

baseURL?

string

default='/api/' base url prefix, override with SERVER_API_URL env

GRAB-URL.ts:602

cancelOngoingIfNew?

boolean

default=true Cancel previous requests to same path

GRAB-URL.ts:604

cancelNewIfOngoing?

boolean

default=false Cancel if a request to path is in progress

GRAB-URL.ts:606

rateLimit?

number

default=false If set, how many seconds to wait between requests

GRAB-URL.ts:608

debug?

boolean

default=false Whether to log the request and response

GRAB-URL.ts:610

infiniteScroll?

[string, string, string]

default=null [page key, response field to concatenate, element with results]

GRAB-URL.ts:612

setDefaults?

boolean

default=false Pass this with options to set those options as defaults for all requests

GRAB-URL.ts:614

retryAttempts?

number

default=0 Retry failed requests this many times

GRAB-URL.ts:616

logger()?

(...args: any[]) => void

default=log Custom logger to override the built-in color JSON log()

GRAB-URL.ts:618

onRequest()?

(...args: any[]) => any

Set with defaults to modify each request data. Takes and returns in order: path, response, params, fetchParams

GRAB-URL.ts:620

onResponse()?

(...args: any[]) => any

Set with defaults to modify each request data. Takes and returns in order: path, response, params, fetchParams

GRAB-URL.ts:622

onError()?

(...args: any[]) => any

Set with defaults to modify each request data. Takes and returns in order: error, path, params

GRAB-URL.ts:624

onStream()?

(...args: any[]) => any

Set with defaults to process the response as a stream (i.e., for instant unzip)

GRAB-URL.ts:626

repeat?

number

default=0 Repeat request this many times

GRAB-URL.ts:628

repeatEvery?

number

default=null Repeat request every seconds

GRAB-URL.ts:630

debounce?

number

default=0 Seconds to debounce request, wait to execute so that other requests may override

GRAB-URL.ts:632

regrabOnStale?

boolean

default=false Refetch when cache is past cacheForTime

GRAB-URL.ts:634

regrabOnFocus?

boolean

default=false Refetch on window refocus

GRAB-URL.ts:636

regrabOnNetwork?

boolean

default=false Refetch on network change

GRAB-URL.ts:638

post?

boolean

shortcut for method: "POST"

GRAB-URL.ts:640

put?

boolean

shortcut for method: "PUT"

GRAB-URL.ts:642

patch?

boolean

shortcut for method: "PATCH"

GRAB-URL.ts:644

body?

any

default=null The body of the POST/PUT/PATCH request (can be passed into main)

GRAB-URL.ts:646

Type Parameters

TResponse

any

TParams

any


grab()

function grab<TResponse, TParams>(path: string, options?: GrabOptions<TResponse, TParams>): Promise<GrabResponse<TResponse>>;

Defined in: GRAB-URL.ts:88

GRAB: Generate Request to API from Browser

GrabAPILogo

  1. GRAB is the FBEST Request Manager: Functionally Brilliant, Elegantly Simple Tool: One Function, no dependencies, minimalist syntax, more features than alternatives
  2. Auto-JSON Convert: Pass parameters and get response or error in JSON, handling other data types as is.
  3. isLoading Status: Sets .isLoading=true on the pre-initialized response object so you can show a "Loading..." in any framework
  4. Debug Logging: Adds global log() and prints colored JSON structure, response, timing for requests in test.
  5. Mock Server Support: Configure window.grab.mock for development and testing environments
  6. Cancel Duplicates: Prevent this request if one is ongoing to same path & params, or cancel the ongoing request.
  7. Timeout & Retry: Customizable request timeout, default 30s, and auto-retry on error
  8. DevTools: Ctrl+I overlays webpage with devtools showing all requests and responses, timing, and JSON structure.
  9. Request History: Stores all request and response data in global grab.log object
  10. Pagination Infinite Scroll: Built-in pagination for infinite scroll to auto-load and merge next result page, with scroll position recovery.
  11. Base URL Based on Environment: Configure grab.defaults.baseURL once at the top, overide with SERVER_API_URL in .env.
  12. Frontend Cache: Set cache headers and retrieve from frontend memory for repeat requests to static data.
  13. Regrab On Error: Regrab on timeout error, or on window refocus, or on network change, or on stale data.
  14. Framework Agnostic: Alternatives like TanStack work only in component initialization and depend on React & others.
  15. Globals: Adds to window in browser or global in Node.js so you only import once: grab(), log(), grab.log, grab.mock, grab.defaults
  16. TypeScript Tooltips: Developers can hover over option names and autocomplete TypeScript.
  17. Request Stategies: 🎯 Examples show common stategies like debounce, repeat, proxy, unit tests, interceptors, file upload, etc
  18. Rate Limiting: Built-in rate limiting to prevent multi-click cascading responses, require to wait seconds between requests.
  19. Repeat: Repeat request this many times, or repeat every X seconds to poll for updates.
  20. Loading Icons: Import from grab-url/icons to get enhanced animated loading icons.

Type Parameters

TResponse

any

TParams

any

Parameters

path

string

The full URL path OR relative path on this server after grab.defaults.baseURL

options?

GrabOptions<TResponse, TParams>

Request params for GET or body for POST/PUT/PATCH and utility options

Returns

Promise<GrabResponse<TResponse>>

The response object with resulting data or .error if error.

Author

vtempest (2025)

See

🎯 Examples 📑 Docs

Example

import grab from 'grab-url';
let res = {};
await grab('search', {
  response: res,
  query: "search words"
})

default

Renames and re-exports grab


log

Re-exports log


showAlert

Re-exports showAlert


printJSONStructure

Re-exports printJSONStructure