Skip to content

Commit e204eff

Browse files
authored
Encourage passing fetch option rather than patching the instance (#183)
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.
1 parent a9e4326 commit e204eff

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,18 +127,20 @@ import fetch from "cross-fetch";
127127
const replicate = new Replicate({ fetch });
128128
```
129129

130-
You can override the `fetch` property to add custom behavior to client requests,
130+
You can also use the `fetch` option to add custom behavior to client requests,
131131
such as injecting headers or adding log statements.
132132

133133
```js
134-
replicate.fetch = (url, options) => {
134+
const customFetch = (url, options) => {
135135
const headers = options && options.headers ? { ...options.headers } : {};
136136
headers["X-Custom-Header"] = "some value";
137137

138138
console.log("fetch", { url, ...options, headers });
139139

140140
return fetch(url, { ...options, headers });
141141
};
142+
143+
const replicate = new Replicate({ fetch: customFetch });
142144
```
143145

144146
### `replicate.run`

0 commit comments

Comments
 (0)