@arunvaradharajalu/common.decorators
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

@arunvaradharajalu/common.decorators

npm version GitHub issues GitHub license

This package provides TypeScript decorators for defining controllers, route methods, and middleware for Express applications.

Installation

Install using npm:

npm install @arunvaradharajalu/common.decorators

Usage

Controller Decorator

The Controller decorator allows you to define a controller class with route handlers:

import { Controller } from '@arunvaradharajalu/common.decorators';

@Controller('/api/users')
class UserController {
  // Define route handlers here using other route decorators
}

Route Method Decorators

Use route method decorators like Get, Post, Put, etc., to define HTTP methods and their corresponding paths:

import { Get, Post, Controller } from '@arunvaradharajalu/common.decorators';

@Controller('/api/users')
class UserController {
  @Get('/')
  getAllUsers(req: Request, res: Response) {
    // Handle GET request to fetch all users
  }

  @Post('/')
  createUser(req: Request, res: Response) {
    // Handle POST request to create a new user
  }
}

Middleware Decorator

The Use decorator adds middleware to a route handler:

import { Get, Use, Controller } from '@arunvaradharajalu/common.decorators';

@Controller('/api/users')
class UserController {
  @Get('/')
  @Use(authMiddleware)
  getAllUsers(req: Request, res: Response) {
    // This route uses authMiddleware
  }
}

Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue for bug fixes, improvements, or new features.

Author

Arun Varadharajalu

License

This project is licensed under the ISC License.

Readme

Keywords

Package Sidebar

Install

npm i @arunvaradharajalu/common.decorators

Weekly Downloads

1

Version

1.1.0

License

ISC

Unpacked Size

13.7 kB

Total Files

17

Last publish

Collaborators

  • arunvaradharajalu