@exobase/use-headers
v1.0.0-rc.25
Published
Exobase hook to parse and validate header values in a request
Downloads
142
Readme
title: 'useHeaders' description: 'A hook to parse and validate request headers' group: 'Hooks' badge: 'Validation'
Provides a hook to parse and validate headers in the request.
Install
yarn add @exobase/use-headers
# or
yarn add @exobase/hooks
Import
import { useHeaders } from '@exobase/use-headers'
// or
import { useHeaders } from '@exobase/hooks'
Import
import { useHeaders } from '@exobase/use-headers'
import { useHeaders } from '@exobase/hooks'
Usage
import { compose } from 'radash'
import type { Props } from '@exobase/core'
import { useHeaders } from '@exobase/use-headers'
import { useLambda } from '@exobase/use-lambda'
type Args = {
'x-request-timestamp': number
'x-api-key': string
}
const createAccount = async ({ args }: Props) => {
await db.users.add({
username: args.username,
password: args.password
})
}
export default compose(
useLambda(),
useHeaders(z => ({
'x-request-timestamp': zod.number(),
'x-api-key': zod.string()
})),
createAccount
)