public

Pattern matching routes with nest.js

Did you know that you can use regular expression in your request decorators such as @Get(()? This is supported out of the box, no special middleware needed.

Latest Post Bulk remove git tags by Matthew Davis public

Why allow a request to make it past the route matching process and in to the validation middleware when you're using validation pipes in your request decorators?

Instead add pattern matching to the route itself! This will prevent the request from making it further down the stack and executing validation logic straight away.

Did you know that you can use regular expression in your request decorators such as @Get(<path>(<regex pattern>)? This is supported out of the box, no special middleware needed.

Examples

Match the route that is passing a v4 uuid as a parameter

http://matthewdavis.io/befbbc34-8bce-4b31-b0fb-927ff5b2b2a5
Example URL
@Get('/:cameraId([a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12})')
public get(@Param('cameraId') cameraId: string): Promise<Camera> {
    //
}
Request decorator

Matthew Davis

Published 23 days ago