Single function client for the Scryfall API, adhering to the usage guidelines for request spacing and caching.
scry.configurescry'/cards/named?exact=grizzly+bears' // Promise<>.then.catch
You must call
scry.configure(...) providing either a Redis client object (for default cache implementation) or your own cache implementation.
configure only needs to be called once, at the entry point of your application, since the
scry function is a shared singleton by design (in order to enforce global cache usage + rate limits).
For successful searches the promise will resolve with a JS object as documented in the Scryfall API docs. Responses with HTTP error codes (including searches that don't match any results) will reject the promise with an AxiosError.
Typescript types for Scryfall API objects are not providedyet. If you want to specify a type for your expected response, you can do so using
scry<MyType>(...), or verify responses with something like io-ts.
The full selection of configuration options is shown below:
Custom cache implementations must match the following type (which is exported):
The default cache implementation simply wraps the provided Redis client's
set methods, using Redis's built-in cache expiry (i.e.
SET key value EX duration).