You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| baseURL | The base URL for the RPC. The service path will be appended to this string. | string | "https://my.server.com/"|
212
+
| headers | HTTP headers to include in the RPC. | Record<string, string> | { "idempotency-key": "foo" } |
213
+
| prefix | A path prefix such as "/my/custom/prefix". Defaults to "/twirp", but can be set to "". | string | "/my/custom/prefix" |
214
+
| rpcTransport | The transport to use for the RPC. Defaults to `fetch`. Overrides must conform to a subset of the fetch interface defined by the `RpcTransport` type. |`RpcTransport`|`fetch`|
214
215
215
216
##### Example
216
217
@@ -271,6 +272,21 @@ const hat = await MakeHat(
271
272
console.log(hat);
272
273
```
273
274
275
+
##### rpcTransport
276
+
277
+
Twirp abstracts many network details from clients. Sometimes you will want more control over the underlying network request. For these cases, TwirpScript exposes `rpcTransport`.
278
+
279
+
`rpcTransport` can be used to customize the `fetch` request made. For example, setting `fetch`'s [credentials](https://developer.mozilla.org/en-US/docs/Web/API/fetch#credentials) option to include (which will include cookies in cross origin requests):
280
+
281
+
```ts
282
+
import { client } from"twirpscript";
283
+
284
+
client.rpcTransport= (url, opts) =>
285
+
fetch(url, { ...opts, credentials: "include" });
286
+
```
287
+
288
+
`rpcTransport` could also be used to replace `fetch` use entirely with something like `axios` or an [https agent](https://nodejs.org/api/https.html#https_class_https_agent).
289
+
274
290
#### Server
275
291
276
292
Servers can be configured by passing a configuration object to `createTwirpServer`.
0 commit comments