From 6be186b9ddc119adf35b29736610acea2b91c89c Mon Sep 17 00:00:00 2001 From: Mattt Zmuda Date: Fri, 7 Jul 2023 05:38:31 -0700 Subject: [PATCH] Document how to customize client requests by setting fetch property --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index b141337..497f486 100644 --- a/README.md +++ b/README.md @@ -131,6 +131,20 @@ const replicate = new Replicate({ }); ``` +You can override the `fetch` property to add custom behavior to client requests, +such as injecting headers or adding log statements. + +```js +client.fetch = (url, options) => { + const headers = new Headers(options && options.headers); + headers.append("X-Custom-Header", "some value"); + + console.log("fetch", { url, ...options, headers }); + + return fetch(url, { ...options, headers }); +}; +``` + ### `replicate.models.get` ```js