1.0.0-rc.25 • Published 3 months ago

@exobase/use-json-body v1.0.0-rc.25

Weekly downloads
-
License
MIT
Repository
-
Last release
3 months ago

title: 'useJsonBody' description: 'A hook to parse and validate a request body' group: 'Hooks'

badge: 'Validation'

Provides a hook to parse and validate request arguments from the json body.

Install

yarn add @exobase/use-json-body
# or
yarn add @exobase/hooks

Import

import { useJsonBody } from '@exobase/use-json-body'
// or
import { useJsonBody } from '@exobase/hooks'

Usage

If you're writing Exobase endpoints in Typescript you'll want to import the Props type.

import { compose } from 'radash'
import type { Props } from '@exobase/core'
import { useJsonBody } from '@exobase/use-json-body'
import { useLambda } from '@exobase/use-lambda'

type Args = {
  username: string
  password: string
}

const createAccount = async ({ args }: Props) => {
  // await db.users.add({
  //   username: args.username,
  //   password: args.password
  // })
}

const STRONG = /^(?=.*[0-9])(?=.*[!@#$%^&*])[a-zA-Z0-9!@#$%^&*]{6,16}$/

export default compose(
  useLambda(),
  useJsonBody(z => ({
    username: z.string(),
    password: z.string().refine(p => STRONG.test(p), {
      message: 'Password is too weak'
    })
  })),
  createAccount
)
1.0.0-rc.25

3 months ago

1.0.0-rc.24

3 months ago

1.0.0-rc.20

3 months ago

1.0.0-rc.23

3 months ago

1.0.0-rc.22

3 months ago

1.0.0-rc.21

3 months ago

1.0.0-rc.18

9 months ago

1.0.0-rc.17

1 year ago

1.0.0-rc.16

1 year ago

1.0.0-rc.15

1 year ago

1.0.0-rc.14

1 year ago

1.0.0-rc.13

1 year ago

1.0.0-rc.12

1 year ago

1.0.0-rc.9

1 year ago

1.0.0-rc.7

1 year ago

1.0.0-rc.8

1 year ago

1.0.0-rc.11

1 year ago

1.0.0-rc.10

1 year ago

1.0.0-rc.6

1 year ago

1.0.0-rc.5

1 year ago

1.0.0-rc.4

1 year ago