Prim+RPC supports H3 which is the foundation of the Nitro server, used by the Nuxt framework. This means that Prim+RPC
works with all of these frameworks. Setup between the three frameworks is mostly the same but with slightly different
naming patterns. We’ll cover all frameworks separately to reduce confusion.
In all three frameworks, we will be working with the following functions to be used from the server:
H3 is the easiest to set up since it just a simple HTTP server framework without file naming patterns. Setup is straight
In this example, it’s assumed that you are using Node but H3 can be used in Deno and Bun as well.
This configuration does not yet support sending files back to the client yet but we can add support by installing a new
module called form-data and configuring it with our server:
We can test this out by issuing a new request from the command line:
Nitro is the same server framework used in Nuxt. Setup is similar to H3 except routing in Nitro is file-based. In order
to serve functions used with Prim+RPC, we will need to create a catch-all route (take note of the filename):
Similar to H3, we can also add file download support by using the form-data module:
We can test this out by issuing a new request from the command line (change port as needed):
Prim+RPC setup in Nuxt is almost identical to Nitro except all routes are prefixed with /server. Routing in Nuxt
is file-based and in order to serve functions used with Prim+RPC, we will need to create a catch-all route (take note of
Similar to H3 and Nitro, we can also add file download support by using the form-data module:
Since Nuxt is a fullstack framework, running on both the server and the client, this means that the Prim+RPC client may
run on either the server or the client.
On the server, you can avoid a network request from the client by conditionally passing the module to the client. Below
is an example of how you may do so, using the Fetch API method plugin:
We defined this function as a composable (using the “composables” folder) so now we can use this client anywhere in our
application, without needing to import it: