Utility class for registering routes in the Fastify application.

Constructors

Methods

Constructors

Methods

  • Registers a route with the given HTTP method, path, and handler in the Fastify application.

    Parameters

    • app: FastifyInstance<
          RawServerDefault,
          IncomingMessage,
          ServerResponse<IncomingMessage>,
          FastifyBaseLogger,
          FastifyTypeProviderDefault,
      >

      The Fastify instance to register the route with.

    • method: HttpMethod

      The HTTP method for the route (e.g., 'GET', 'POST', 'PUT', 'DELETE').

    • path: string

      The URL path for the route.

    • handler: (
          request: FastifyRequest<
              RouteGenericInterface,
              RawServerDefault,
              IncomingMessage,
              FastifySchema,
              FastifyTypeProviderDefault,
              unknown,
              FastifyBaseLogger,
              ResolveFastifyRequestType<
                  FastifyTypeProviderDefault,
                  FastifySchema,
                  RouteGenericInterface,
              >,
          >,
          reply: FastifyReply<
              RouteGenericInterface,
              RawServerDefault,
              IncomingMessage,
              ServerResponse<IncomingMessage>,
              unknown,
              FastifySchema,
              FastifyTypeProviderDefault,
              unknown,
          >,
      ) => Promise<void>

      The handler function to process requests to the route.

    Returns void

    AppServerRoute.registerRoute(app, 'GET', '/hello', async (request, reply) => {
    reply.send({ message: 'Hello, world!' });
    });