From fc0f6ca303bb107a477e7f43cc94447f0cf54459 Mon Sep 17 00:00:00 2001 From: Aron Carroll Date: Sun, 7 Jan 2024 21:05:48 +0000 Subject: [PATCH] Encourage passing `fetch` option rather than patching the instance Minor stylistic change, but means that we're not committing to a `replicate.fetch` top level function and instead encouraging any custom functionality to be passed to the constructor rather than monkey patching the api. --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4d6e7280..bd7e43d7 100644 --- a/README.md +++ b/README.md @@ -127,11 +127,11 @@ import fetch from "cross-fetch"; const replicate = new Replicate({ fetch }); ``` -You can override the `fetch` property to add custom behavior to client requests, +You can also use the `fetch` option to add custom behavior to client requests, such as injecting headers or adding log statements. ```js -replicate.fetch = (url, options) => { +const customFetch = (url, options) => { const headers = options && options.headers ? { ...options.headers } : {}; headers["X-Custom-Header"] = "some value"; @@ -139,6 +139,8 @@ replicate.fetch = (url, options) => { return fetch(url, { ...options, headers }); }; + +const replicate = new Replicate({ fetch: customFetch }); ``` ### `replicate.run`