request.routeOptions

Metadata about the matched route, including its URL pattern and config.

Since Fastify 5 Spec ↗

Syntax

request.routeOptions

Returns

object — Object with method, url, schema, and config of the route.

Examples

import Fastify from 'fastify';

const app = Fastify();

app.addHook('onResponse', async (req, reply) => {
  req.log.info({
    route: req.routeOptions.url,
    status: reply.statusCode,
  });
});

app.get('/cats/:id', { config: { auth: true } }, async () => ({}));

Notes

Use request.routeOptions.url for the pattern (/cats/:id) rather than the concrete path. request.routeOptions.config carries per-route config you passed when registering, useful for hooks.