# @exobase/use-path-params

> Exobase path param parsing hook

Latest version **1.0.0-rc.33** (published 2024-07-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install @exobase/use-path-params
pnpm add @exobase/use-path-params
yarn add @exobase/use-path-params
bun add @exobase/use-path-params
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0-rc.33 |
| Published | 2024-07-08 |
| First published | 2022-10-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 17.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 21 |
| Author | rayepps |
| Maintainers | rayepps |

## Links

- npm: https://www.npmjs.com/package/@exobase/use-path-params
- Repository: https://github.com/rayepps/exobase-js
- Homepage: https://github.com/rayepps/exobase-js#readme
- Issues: https://github.com/rayepps/exobase-js/issues
- npm.io page: https://npm.io/package/@exobase/use-path-params

## Dependencies (1)

- [@exobase/core](https://npm.io/package/@exobase/core.md) ^1.0.0-rc.31

## Recent versions

- 1.0.0-rc.33 (latest) — 2024-07-08
- 1.0.0-rc.32 — 2024-02-21
- 1.0.0-rc.31 — 2024-02-20
- 1.0.0-rc.30 — 2024-02-20
- 1.0.0-rc.29 — 2024-02-20
- 1.0.0-rc.28 — 2024-02-19
- 1.0.0-rc.27 — 2024-02-19
- 1.0.0-rc.25 — 2023-08-17
- 1.0.0-rc.24 — 2023-03-07
- 1.0.0-rc.23 — 2023-03-02
- 1.0.0-rc.22 — 2023-03-01
- 1.0.0-rc.21 — 2023-03-01
- 1.0.0-rc.20 — 2023-02-22
- 1.0.0-rc.19 — 2023-02-22
- 1.0.0-rc.18 — 2023-01-08
- … 16 more at https://npm.io/package/@exobase/use-path-params/versions

## README

---
title: 'usePathParams'
description: 'A hook to validate request path parameters'
group: 'Hooks'
---

An Exobase hook that validates path parameters in the request.

## Install

```sh
yarn add @exobase/use-path-params
# or
yarn add @exobase/hooks
```

## Import

```ts
import { usePathParams } from '@exobase/use-path-params'
// or
import { usePathParams } from '@exobase/hooks'
```

## Usage

```ts
import { compose } from 'radash'
import type { Props } from '@exobase/core'
import { useNext } from '@exobase/use-next'
import { usePathParams } from '@exobase/use-path-params'

export const findBookById = async (props: Props) => {
  return db.books.find(props.args.bookId)
}

export default compose(
  useNext(),
  usePathParams(z => ({
    libraryId: z.string(),
    bookId: z.string().tranform(id => parseInt(id)),
  }))
  findBookById
)
```

when called with

```sh
curl /api/libraries/ny-public-library/books/3328
```

In some cases, you may need to parse the path params first. Sometimes the framework + root hook will do the param parsing. In other cases the `useRouter` hook, if you use it, will do the param parsing. If you're using AWS Lambda (without a router) there is no built in path param utility so you'll need to parse the path params manually using `usePathParamsParser`.

```ts
import { compose } from 'radash'
import type { Props } from '@exobase/core'
import { useLambda } from '@exobase/use-lambda'
import { usePathParamsParser } from '@exobase/use-path-params-parser'
import { usePathParams } from '@exobase/use-path-params'

export const findBookById = async (props: Props) => {
  return db.books.find(props.args.bookId)
}

export default compose(
  useLambda(),
  usePathParamsParser('/libraries/{libraryId}/books/{bookId}'),
  usePathParams(z => ({
    libraryId: z.string(),
    bookId: z.string().tranform(id => parseInt(id)),
  }))
  findBookById
)
```

---
_Source: https://npm.io/package/@exobase/use-path-params · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
