Provides a hook to parse and validate query string values in the request.
Install
Yarn
yarn add @exobase/use-query-args
or install useQueryArgs
with all other Exobase provided hooks:
yarn add @exobase/hooks
Usage
import { compose } from 'radash'
import type { Props } from '@exobase/core'
import { useQueryArgs } from '@exobase/use-query-args'
import { useLambda } from '@exobase/use-lambda'
type Args = {
id: number
format: 'basic' | 'detailed'
}
const getAccount = async ({ args }: Props) => {
const { id, format } = args
const account = await db.accounts.find(id)
return format === 'basic'
? mappers.Account.basic(account)
: mappers.Account.detailed(account)
}
export default compose(
useLambda(),
useQueryArgs(z => ({
id: zod.string(),
format: zod.string()
})),
getAccount
)