Controller

The InversifyJS Express utils allow us to declare controllers using what is known as declarative routing. Instead of declaring Router instances, we can annotate a controller class using some decorators. The metadata generated by the decorators is later used by the InversifyJS express utils to generate the Router instances for us.

The following example uses the following decorators:

  • @controller(path): It is used to declare the path of a router
  • @inject(type): It is used to inject dependencies into a class
  • @httpGet(subpath): It is used to declare a route handler for HTTP GET requests
  • @httpPost(subpath): It is used to declare a route handler for HTTP POST requests
  • @response(): It is used to pass the response object to a route handler ...

Get Learning TypeScript 2.x - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.