How to include custom headers in the request sent? #139
-
I am going through https://www.rspc.dev/client but I do not see a way to send custom headers in the request. For example, if I wish to send a |
Beta Was this translation helpful? Give feedback.
Answered by
oscartbeaumont
Mar 12, 2023
Replies: 1 comment
-
You can provide a custom fetch implementation shown here and extend the headers array. So like the following: import { createClient, FetchTransport } from "@rspc/client";
import type { Procedures } from "./bindings.ts"; // The bindings exported from your Rust code!
const client = createClient<Procedures>({
transport: new FetchTransport(
"http://localhost:4000/rspc",
// Include Cookies for cross-origin requests
(input, init) => fetch(input, { ...init, headers: { ...init.headers, "X-Demo": "123" })
),
}); In a future update, I will probs add a nicer way to do this because forgetting to pass through the |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
oscartbeaumont
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can provide a custom fetch implementation shown here and extend the headers array.
So like the following:
In a future update, I will probs add a nicer way to do this because forgetting to pass through the
init.headers
will likely cause people some strife.