Prim+RPC supports Remix by defining an API route. You may also choose to use Remix with an Express server, for which Prim+RPC also has a plugin. The first step is to create some function the server that you’d like to expose to the client:
You may configure Prim+RPC with Remix by using a catch-all route in your app directory. You may name this route anything that you’d like, just remember to set the corresponding Prim+RPC prefix option to match:
You may choose to name your route app/routes/prim.$/route.ts
or app/routes/prim.$.ts
, both are valid route names in Remix.
Your Prim+RPC server is now set up! Remix is a fullstack framework that can run on both server and client, which means the Prim+RPC client may be called on the server as well as the client.
On the server, you can avoid a network request from the client by conditionally passing the module. Below is an example of how you may do so, using the Fetch API method plugin:
Now this exported client may used from anywhere in your project. We’ll demonstrate usage of the client from both the server and the client.
Now we are all set up!
You may also choose a compatible method plugin:
Report an Issue