Skip to content
On this page

useQueryParameters

Composable to access Query Parameters

Usage

Single Parameter

import { use, useQueryParameters } from '@serverless-use/apigw'

export const handler = use(async () => {
  const { get } = useQueryParameters()
  const name = get('name')

  return {
   name
  }
})

All Parameters

import { use, useQueryParameters } from '@serverless-use/apigw'

export const handler = use(async () => {
  const { queryParameters } = useQueryParameters()

  return {
   queryParameters
  }
})

Typed Parameters

import { use, useQueryParameters } from '@serverless-use/apigw'

export const handler = use(async () => {
  const { get } = useQueryParameters<{ name?: string }>()

  // TS ERROR!
  // Argument of type '"foo"' is not assignable to parameter of type '"name"'.
  const foo = get('foo')

  return {
    foo,
  }
})