Skip to content

How to include custom headers in the request sent? #139

Closed Answered by oscartbeaumont
IgnisDa asked this question in rspc Help
Discussion options

You must be logged in to vote

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 init.headers will likely cause people some strife.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by oscartbeaumont
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants