Skip to content

setSlug

hooks
Source Code | Documentation

Extracts URL route parameters (slugs) and sets them on params.query. For example, given a route /stores/:storeId, this hook copies the resolved storeId value from params.route into the query. Only applies to the rest provider.

ts
  import { 
setSlug
} from 'feathers-utils/hooks';

Example

ts
import { setSlug } from 'feathers-utils/hooks'

app.service('stores/:storeId/products').hooks({
  before: { all: [setSlug('storeId')] }
})

Type declaration

Show Type Declarations
ts
/**
 * Extracts URL route parameters (slugs) and sets them on `params.query`.
 * For example, given a route `/stores/:storeId`, this hook copies the resolved
 * `storeId` value from `params.route` into the query. Only applies to the `rest` provider.
 *
 * @example
 * ```ts
 *
 *
 * app.service('stores/:storeId/products').hooks({
 *   before: { all: [setSlug('storeId')] }
 * })
 * ```
 *
 * @see https://utils.feathersjs.com/hooks/set-slug.html
 */
export declare const setSlug: <H extends HookContext = HookContext>(
  slug: string,
  fieldName?: string,
) => (context: H, next?: NextFunction) => any
ArgumentTypeDescription
slugstring
fieldNamestring
typemethodsmulti
before, after, aroundallyes

Released under the MIT License.