Skip to content

Decorator (Backend)

Medium — good to knowBackend

ELI5 — The Vibe Check

A backend decorator wraps a function or class to add extra behavior without modifying the original. In NestJS, @Controller(), @Get(), @Injectable() are all decorators. In Python, @app.route and @login_required are decorators. They're like stickers you slap on code to give it superpowers.

Real Talk

In backend frameworks, decorators are functions that modify or enhance classes, methods, or properties using the decorator pattern. They enable declarative programming by annotating code with cross-cutting concerns like routing, authentication, caching, and validation. TypeScript decorators (NestJS) and Python decorators (FastAPI, Flask) are the most common implementations.

Show Me The Code

@Controller('users')
class UserController {
  @Get(':id')
  @UseGuards(AuthGuard)
  @Cacheable(60)
  async getUser(@Param('id') id: string) {
    return this.userService.findById(id);
  }
}

When You'll Hear This

"Add the @Cacheable decorator to cache that endpoint for 60 seconds." / "NestJS decorators handle routing, auth, and validation declaratively."

Made with passive-aggressive love by manoga.digital. Powered by Claude.