How to use fastify-decorators - 10 common examples

To help you get started, we’ve selected a few fastify-decorators examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github L2jLiga / fastify-decorators / test / bootstrap-app / get.handler.ts View on Github external
/**
 * @license
 * Copyright Andrey Chalkin  (https://github.com/L2jLiga). All Rights Reserved.
 *
 * Use of this source code is governed by an MIT-style license that can be
 * found in the LICENSE file at https://github.com/L2jLiga/fastify-decorators/blob/master/LICENSE
 */

import { GET, RequestHandler } from 'fastify-decorators';

@GET('/get')
class GetHandler extends RequestHandler {
    async handle() {
        return { message: 'OK!' };
    }
}

export = GetHandler;
github L2jLiga / fastify-decorators / test / bootstrap-app / other / request.controller.ts View on Github external
* Use of this source code is governed by an MIT-style license that can be
 * found in the LICENSE file at https://github.com/L2jLiga/fastify-decorators/blob/master/LICENSE
 */

import { FastifyReply, FastifyRequest } from 'fastify';
import { AbstractController, Controller, ControllerType, GET, Hook } from 'fastify-decorators';
import { IncomingMessage, ServerResponse } from 'http';

@Controller({
    route: '/request',
    type: ControllerType.REQUEST
})
class RequestController extends AbstractController {
    private callsCount = 0;

    @GET('/index')
    async indexHandler() {
        this.instance.log.info('Handled request to /request/index');

        this.callsCount++;
        return 'Request controller: index handler, calls count: ' + this.callsCount;
    }

    @Hook('onSend')
    async hidePoweredBy(request: FastifyRequest, reply: FastifyReply) {
        reply.header('X-Powered-By', 'nodejs');
    }
}

export = RequestController;
github L2jLiga / fastify-decorators / test / bootstrap-app / singleton.controller.ts View on Github external
* @license
 * Copyright Andrey Chalkin  (https://github.com/L2jLiga). All Rights Reserved.
 *
 * Use of this source code is governed by an MIT-style license that can be
 * found in the LICENSE file at https://github.com/L2jLiga/fastify-decorators/blob/master/LICENSE
 */

import { FastifyReply, FastifyRequest } from 'fastify';
import { IncomingMessage, ServerResponse } from 'http';
import { Controller, GET, Hook } from 'fastify-decorators';

@Controller('/ctrl')
export default class SingletonController {
    private callsCount = 0;

    @GET('/index')
    async index() {
        this.callsCount++;

        return 'Singleton controller: index handler, calls count: ' + this.callsCount;
    }

    @Hook('onSend')
    async hidePoweredBy(request: FastifyRequest, reply: FastifyReply) {
        reply.header('X-Powered-By', 'nodejs');
    }
}
github L2jLiga / fastify-decorators / test / bootstrap-app / other / request.controller.ts View on Github external
/**
 * @license
 * Copyright Andrey Chalkin  (https://github.com/L2jLiga). All Rights Reserved.
 *
 * Use of this source code is governed by an MIT-style license that can be
 * found in the LICENSE file at https://github.com/L2jLiga/fastify-decorators/blob/master/LICENSE
 */

import { FastifyReply, FastifyRequest } from 'fastify';
import { AbstractController, Controller, ControllerType, GET, Hook } from 'fastify-decorators';
import { IncomingMessage, ServerResponse } from 'http';

@Controller({
    route: '/request',
    type: ControllerType.REQUEST
})
class RequestController extends AbstractController {
    private callsCount = 0;

    @GET('/index')
    async indexHandler() {
        this.instance.log.info('Handled request to /request/index');

        this.callsCount++;
        return 'Request controller: index handler, calls count: ' + this.callsCount;
    }

    @Hook('onSend')
    async hidePoweredBy(request: FastifyRequest, reply: FastifyReply) {
github L2jLiga / fastify-decorators / test / bootstrap-app / singleton.controller.ts View on Github external
/**
 * @license
 * Copyright Andrey Chalkin  (https://github.com/L2jLiga). All Rights Reserved.
 *
 * Use of this source code is governed by an MIT-style license that can be
 * found in the LICENSE file at https://github.com/L2jLiga/fastify-decorators/blob/master/LICENSE
 */

import { FastifyReply, FastifyRequest } from 'fastify';
import { IncomingMessage, ServerResponse } from 'http';
import { Controller, GET, Hook } from 'fastify-decorators';

@Controller('/ctrl')
export default class SingletonController {
    private callsCount = 0;

    @GET('/index')
    async index() {
        this.callsCount++;

        return 'Singleton controller: index handler, calls count: ' + this.callsCount;
    }

    @Hook('onSend')
    async hidePoweredBy(request: FastifyRequest, reply: FastifyReply) {
        reply.header('X-Powered-By', 'nodejs');
    }
}
github L2jLiga / fastify-decorators / test / bootstrap-app / other / request.controller.ts View on Github external
@Controller({
    route: '/request',
    type: ControllerType.REQUEST
})
class RequestController extends AbstractController {
    private callsCount = 0;

    @GET('/index')
    async indexHandler() {
        this.instance.log.info('Handled request to /request/index');

        this.callsCount++;
        return 'Request controller: index handler, calls count: ' + this.callsCount;
    }

    @Hook('onSend')
    async hidePoweredBy(request: FastifyRequest, reply: FastifyReply) {
        reply.header('X-Powered-By', 'nodejs');
    }
}

export = RequestController;
github L2jLiga / fastify-decorators / test / bootstrap-app / singleton.controller.ts View on Github external
import { FastifyReply, FastifyRequest } from 'fastify';
import { IncomingMessage, ServerResponse } from 'http';
import { Controller, GET, Hook } from 'fastify-decorators';

@Controller('/ctrl')
export default class SingletonController {
    private callsCount = 0;

    @GET('/index')
    async index() {
        this.callsCount++;

        return 'Singleton controller: index handler, calls count: ' + this.callsCount;
    }

    @Hook('onSend')
    async hidePoweredBy(request: FastifyRequest, reply: FastifyReply) {
        reply.header('X-Powered-By', 'nodejs');
    }
}
github L2jLiga / fastify-decorators / test / bootstrap-app / other / post.handler.ts View on Github external
/**
 * @license
 * Copyright Andrey Chalkin  (https://github.com/L2jLiga). All Rights Reserved.
 *
 * Use of this source code is governed by an MIT-style license that can be
 * found in the LICENSE file at https://github.com/L2jLiga/fastify-decorators/blob/master/LICENSE
 */

import { POST, RequestHandler } from 'fastify-decorators';

@POST({
    url: '/post',
    options: {
        schema: {
            response: {
                200: {
                    type: 'object',
                    properties: {
                        message: { type: 'string' }
                    }
                }
            }
        }
    }
})
class PostHandler extends RequestHandler {
    async handle() {
github L2jLiga / fastify-decorators / test / bootstrap-app / other / request.controller.ts View on Github external
/**
 * @license
 * Copyright Andrey Chalkin  (https://github.com/L2jLiga). All Rights Reserved.
 *
 * Use of this source code is governed by an MIT-style license that can be
 * found in the LICENSE file at https://github.com/L2jLiga/fastify-decorators/blob/master/LICENSE
 */

import { FastifyReply, FastifyRequest } from 'fastify';
import { AbstractController, Controller, ControllerType, GET, Hook } from 'fastify-decorators';
import { IncomingMessage, ServerResponse } from 'http';

@Controller({
    route: '/request',
    type: ControllerType.REQUEST
})
class RequestController extends AbstractController {
    private callsCount = 0;

    @GET('/index')
    async indexHandler() {
        this.instance.log.info('Handled request to /request/index');

        this.callsCount++;
        return 'Request controller: index handler, calls count: ' + this.callsCount;
    }

    @Hook('onSend')
    async hidePoweredBy(request: FastifyRequest, reply: FastifyReply) {
        reply.header('X-Powered-By', 'nodejs');
    }
github L2jLiga / fastify-decorators / src / controllers / simple.controller.ts View on Github external
/**
 * @license
 * Copyright Andrey Chalkin  (https://github.com/L2jLiga). All Rights Reserved.
 *
 * Use of this source code is governed by an MIT-style license that can be
 * found in the LICENSE file at https://github.com/L2jLiga/fastify-decorators/blob/master/LICENSE
 */

import { FastifyReply, FastifyRequest } from 'fastify';
import { Controller, GET, Hook } from 'fastify-decorators';
import { IncomingMessage, ServerResponse } from 'http';

@Controller('/demo')
export default class SimpleController {
    @GET({
        url: '/test',
        options: {
            schema: {
                response: {
                    200: {
                        properties: {
                            message: {type: 'string'}
                        }
                    }
                }
            }
        }
    })
    async test(request: FastifyRequest, reply: FastifyReply) {
        return {message: this.message};
    }

fastify-decorators

Framework aimed to provide useful TypeScript decorators to implement controllers, services and request handlers, built with Fastify.

MIT
Latest version published 9 months ago

Package Health Score

74 / 100
Full package analysis