response$

API for the response$ function

This function is used to modify the response headers / cookies without affecting the return type of the function.

Usage

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

export const add = query$(
  ({ payload, request$ }) => {
    const result = payload.a + payload.b
    console.log(request$.headers.get('user-agent'))
    return response$(result, {
      headers: {
        'set-cookie': 'solid-testing=1',
      },
    })
  },
  'add',
  z.object({
    a: z.number(),
    b: z.number(),
  })
)

The return type of this function is still number, but the response headers / cookies are modified.