The Docs.

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

Fetch API

Plugin Details

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

Prim+RPC supports the Fetch API as used in modern JavaScript runtimes like Bun and Deno. Node can also use the Fetch API through the @whatwg-node/* ponyfill and server adapter.

First, you’ll need some module with functions that you’d like to expose to the client:

export function hello() {
	return "Hi from Prim+RPC!"
}
hello.rpc = "idempotent"
 
export default hello

Now we can configure our Prim+RPC server with our module using the Fetch API:

import { createPrimServer } from "@doseofted/prim-rpc"
import { primFetch } from "@doseofted/prim-rpc-plugins/server-fetch"
import * as module from "./functions"
 
const prim = createPrimServer({ module })
const fetch = primFetch({ prim })

The Fetch function will be used with the server of your choice. Choose your runtime:

import { createPrimServer } from "@doseofted/prim-rpc"
import { primFetch } from "@doseofted/prim-rpc-plugins/server-fetch"
import * as module from "./functions"
 
const prim = createPrimServer({ module })
const fetch = primFetch({ prim })
 
// Serves http://localhost:8000/prim
Deno.serve(fetch)

Your server should now be available on the address show above, unless you have changed settings. Take note of the address as will become the client’s endpoint. The /prim prefix may also be different if you’ve configured it in your Prim+RPC server. You can test it out like so:

# Remember to change the address depending on your server
curl "http://localhost:3000/prim"

You may also choose a compatible method plugin:

Report an Issue