npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

gtf-reflected-router

v1.0.11

Published

A TypeScript library that provides decorators for defining and managing Fastify routes in a clean, declarative way.

Readme

GTF Reflected Router

A TypeScript library that provides decorators for defining and managing Fastify routes in a clean, declarative way.

Installation

# Using npm
npm install gtf-reflected-router

# Using yarn
yarn add  gtf-reflected-router

# Using pnpm
pnpm add  gtf-reflected-router

Features

  • TypeScript decorators for all standard HTTP methods
  • Type-safe route definitions
  • Automatic route registration
  • Compatible with Fastify's route options
  • Prevents duplicate routes
  • Parameter decorators for request and response objects

Usage

Basic Example

import { Get, Post, getRoutes } from 'gtf-router-handler';
import fastify from 'fastify';

const app = fastify();

class UserController {
  @Get('/users')
  async getAllUsers(request, reply) {
    return { users: ['John', 'Jane', 'Bob'] };
  }

  @Get('/users/:id')
  async getUserById(request, reply) {
    const { id } = request.params;
    return { id, name: 'John Doe' };
  }

  @Post('/users')
  async createUser(request, reply) {
    // Create a new user
    return { success: true, user: request.body };
  }
}

// Register routes with Fastify
const userController = new UserController();
const routes = getRoutes(UserController);

routes.forEach(route => {
  app.route({
    method: route.method,
    url: route.path,
    handler: userController[route.handler].bind(userController),
    ...route.options
  });
});

app.listen({ port: 3000 });

Using Route Options

import { Post } from 'gtf-reflected-router/decorators';

class ProductController {
  @Post('/products', {
    schema: {
      body: {
        type: 'object',
        required: ['name', 'price'],
        properties: {
          name: { type: 'string' },
          price: { type: 'number' }
        }
      },
      response: {
        200: {
          type: 'object',
          properties: {
            id: { type: 'string' },
            name: { type: 'string' },
            price: { type: 'number' }
          }
        }
      }
    }
  })
  async createProduct(request, reply) {
    // Create product with validation from schema
    return { id: '123', ...request.body };
  }
}

Using Parameter Decorators

import { Get, Post, Request, Response } from 'gtf-reflected-router/decorators';
import { FastifyRequest } from 'fastify';
import { FastifyReply } from 'fastify/types/reply';

class UserController {
  @Get('/users/:id')
  async getUser(@Request() req: FastifyRequest) {
    const { id } = req.params;
    return { id, name: 'John Doe' };
  }

  @Post('/users')
  async createUser(@Request() req: FastifyRequest, @Response() reply: FastifyReply) {
    // Create a new user
    reply.code(201);
    return { success: true, user: req.body };
  }
}

API Reference

HTTP Method Decorators

  • @Get(path, options?) - Register a GET route
  • @Post(path, options?) - Register a POST route
  • @Put(path, options?) - Register a PUT route
  • @Delete(path, options?) - Register a DELETE route
  • @Patch(path, options?) - Register a PATCH route
  • @Head(path, options?) - Register a HEAD route
  • @Options(path, options?) - Register an OPTIONS route

Generic Route Decorator

// @Route(method, path, options?)
function exampleRoute() {
  // This is just an example of how to use the Route decorator
  Route('GET', '/example', { schema: { response: { 200: { type: 'object' } } } });
}

Parameters:

  • method: HTTP method (GET, POST, PUT, etc.)
  • path: Route path (must start with '/')
  • options: Fastify route options (excluding method, url, and handler)

Parameter Decorators

  • @Request() - Injects the FastifyRequest object into the parameter
  • @Response() - Injects the FastifyReply object into the parameter

Utility Functions

  • getRoutes(targetClass): Retrieves all route metadata from a controller class
  • getRequestParams(target, propertyKey): Gets the indices of parameters marked with @Request decorator
  • getResponseParams(target, propertyKey): Gets the indices of parameters marked with @Response decorator

Requirements

  • TypeScript 4.5+
  • reflect-metadata
  • Fastify 5.x