Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Latest commit

 

History

History
45 lines (36 loc) · 1.13 KB

README.MD

File metadata and controls

45 lines (36 loc) · 1.13 KB

This repo is no longer under development, please use MediaKit - https://github.com/solidjs-community/mediakit/tree/main/packages/prpc

pRPC

Write server code in frontend files with built in colocation, middlewares, schema validation and more, everything is type safed and works with SolidStart

Read more at our docs

Query Example

import { middleware$, query$, response$, error$ } from '@prpc/solid'
import { z } from 'zod'

const testMw = middleware$(async ({ request$ }) => {
  const ua = request$.headers.get('user-agent')
  console.log('middleware called on server ', ua)
  if (ua?.includes('bot')) {
    return error$('Bots are not allowed')
  }
  return {
    ua,
  }
})

const myQuery = query$({
  queryFn: ({ request$, ctx$, payload }) => {
    console.log(
      'queryFn called on server ',
      ctx$.ua === request$.headers.get('user-agent'),
      payload
    )
    return response$(payload.num / 2)
  },
  key: 'testQuery',
  middlewares: [testMw],
  schema: z.object({
    num: z.number(),
  }),
})

SolidStart

Read More Here Regarding SolidStart