Api reference

GRAB Options Reference

GRAB Options Reference

GRAB Options Reference

Type declaration

NameTypeDescription

headers?

Record<string, string>

include headers and authorization in the request

response?

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

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

method?

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

default="GET" The HTTP method to use

cache?

boolean

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

cacheForTime?

number

default=60 Seconds to consider data stale and invalidate cache

timeout?

number

default=30 The timeout for the request in seconds

baseURL?

string

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

cancelOngoingIfNew?

boolean

default=true Cancel previous requests to same path

cancelNewIfOngoing?

boolean

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

rateLimit?

number

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

debug?

boolean

default=false Whether to log the request and response

infiniteScroll?

[string, string, string]

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

setDefaults?

boolean

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

retryAttempts?

number

default=0 Retry failed requests this many times

logger()?

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

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

onRequest()?

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

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

onResponse()?

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

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

onError()?

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

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

onStream()?

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

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

repeat?

number

default=0 Repeat request this many times

repeatEvery?

number

default=null Repeat request every seconds

debounce?

number

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

regrabOnStale?

boolean

default=false Refetch when cache is past cacheForTime

regrabOnFocus?

boolean

default=false Refetch on window refocus

regrabOnNetwork?

boolean

default=false Refetch on network change

post?

boolean

shortcut for method: "POST"

put?

boolean

shortcut for method: "PUT"

patch?

boolean

shortcut for method: "PATCH"

body?

any

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

On this page