The Docs.

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

Express

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

The Prim+RPC server can be configured with Express. First, create some module to be shared with server

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

Below is a simple example of how to use this module with Express:

import { createPrimServer } from "@doseofted/prim-rpc"
import { createMethodHandler } from "@doseofted/prim-rpc-plugins/express"
import express from "express"
import * as module from "./functions"
 
const app = express()
 
const methodHandler = createMethodHandler({ app })
createPrimServer({ module, methodHandler })
 
app.listen(3000)

This configuration does not yet support Files and Blobs but we can do so by adding new Express middleware. First, install both formidable and form-data using your chosen package manager. Then you can configure it like so:

import { createPrimServer } from "@doseofted/prim-rpc"
import { createMethodHandler } from "@doseofted/prim-rpc-plugins/express"
import express from "express"
import multipartPlugin from "formidable"
import formDataHandler from "form-data"
 
const app = express()
 
const methodHandler = createMethodHandler({ app, multipartPlugin, formDataHandler })
createPrimServer({ module, methodHandler })
 
app.listen(3000)

Now we can test this out with a simple call from the command line:

curl "http://localhost:3000/prim"

You may also choose a compatible method plugin:

Report an Issue