Skip to content

Controller Decorator

This file defines the Controller class decorator for the @sodacore/core HTTP module. It marks a class as an HTTP controller, attaches necessary metadata for routing, and optionally sets a base path for all routes within the class.


Features

  • Controller Registration: Adds metadata to register the class as an HTTP controller within the Sodacore framework.
  • Base Path Support: Allows specifying an optional base path that will be prefixed to all routes defined in the controller.
  • Service Tagging: Tags the controller as providing HTTP services for internal discovery and routing.

Usage

typescript
import Controller from './decorator/controller';

@Controller('/api/v1/users')
export class UserController {
	// Define HTTP route handler methods here
}

API

Controller(path?: string): ClassDecorator

  • path: (optional) A base path to prefix all routes in the controller.
  • Returns: A class decorator function.

How It Works

  • Sets the type metadata to 'controller' for autowiring.
  • Sets the path metadata under the 'http' namespace to the provided base path.
  • Adds 'http' to the controller's services metadata array for service discovery.

Notes

  • This decorator is intended for use with HTTP controller classes in the Sodacore framework.
  • The base path is optional; if omitted, routes will not be prefixed.
  • The metadata set by this decorator is used by the framework's router to discover and register HTTP endpoints.

Released under the Apache-2.0 License.