This documentation is deprecated. It covers rspc 0.3.0, which is no longer maintained.
Vanilla Client
rspc has multiple different transports which can be used. These dictate how the frontend is able to talk with the backend.
The vanilla client allows you to consume your API on the frontend. This client is the minimal core and it is recommended that you use the React or Solid integration for building application.
To get started first install the minimal runtime package.
Next you need to export the Typescript bindings from your rspc::Router by using either export_ts_bindings or export_ts.
Then you can use the @rspc/client package to consume your API.
Transports
rspc has multiple different transports which can be used. These dictate how the frontend is able to talk with the backend.
Fetch Transport
Transport build on the standard Fetch API. This uses HTTP GET and POST requests under the hood.
rspc will generally use a GET request for queries and POST request for mutations however this isn't guaranteed.
Custom Fetch implementation
Fetch Authentication
Use a custom fetch function to attach credentials. This example assumes getAccessToken() returns your current application token:
The server must verify the token before trusting it. For cookie sessions on another origin, use credentials: "include" as shown above and configure an explicit CORS origin with credentials support. Protect state-changing cookie-authenticated requests against CSRF.
Websocket Transport
This transport sends messages over a standard WebSocket connection after the HTTP upgrade.
Websocket Authentication
The browser WebSocket API does not support arbitrary authorization headers, and this transport has no custom handshake-header callback.
Use a same-origin cookie session if your server authenticates upgrade requests. Validate the origin and authorize each protected operation. Reconnect after a login or logout when the connection's credentials need to change. Use wss:// for an HTTPS site.
If your application needs bearer headers, use FetchTransport for queries and mutations or implement a transport with an explicit authentication exchange. Avoid long-lived tokens in WebSocket URLs.
