The Docs.

Prim+RPC is in prerelease mode and may be unstable until official release.
All Plugins

Fetch API

Plugin Details
  • Plugin Type:
    Method Plugin
  • Transport:
    HTTP
  • Works with:

This covers the client-side Fetch handler. There’s also a server-specific Fetch plugin available to use.

Prim+RPC supports the Fetch API as implemented in all modern browsers.

import { createPrimClient } from "@doseofted/prim-rpc"
import { createMethodPlugin } from "@doseofted/prim-rpc-plugins/browser-fetch"
 
export const client = createPrimClient({
	endpoint: "http://localhost:3000/prim",
	methodPlugin: createMethodPlugin(),
})

Your endpoint may look different depending on your server selection. Check with your server for the correct endpoint.

You may also add types to your client by passing them as a type argument to the client. Always ensure that only types are passed to the client, not the module itself.

import { createPrimClient } from "@doseofted/prim-rpc"
import { createMethodPlugin } from "@doseofted/prim-rpc-plugins/browser-fetch"
import type * as Module from "./functions"
 
export const client = createPrimClient<Module>({
	endpoint: "http://localhost:3000/prim",
	methodPlugin: createMethodPlugin(),
})

The imported types given here is an example and your import will depend on where your types are exported from the server.

Now you may use this client anywhere in your project:

import { client } from "./client"
 
const greeting = await client.hello()
console.log(greeting)

You may also choose a compatible method handler:

Report an Issue