Controllers
Last updated
Last updated
Angel has built-in support for controllers. This is yet another way to define routes in a manageable group, and can be leveraged to structure your application in the format. You can also use the method of any .
The metadata on controller classes is processed via reflection only once, at startup. Do not believe that your controllers will be crippled by reflection during request handling, because that possibility is eliminated by .
The glue that holds it all together is the Expose
annotation:
Most fields are self-explanatory, save for as
and allowNull
. See, request parameters are mapped to function parameters on each handler. If a parameter is null
, an error will be thrown. To prevent this, you can pass its name to allowNull
.
The other is as
. This allows you to specify a custom name for a controller class or action. ResponseContext
contains a method, redirectToAction
that can redirect to a controller action.
If you do not specify an as
, then controllers and actions will be available by their names in code. Reflection is cool, huh?
Rather than extending from Routable
, controllers act as when called. This pseudo-plugin will wire all your routes for you.
Controllers can also interact with . All you have to do is declare a RequestContext
or ResponseContext
as a parameter, and it will be passed to the function.
You can use to de/serialize data to be processed in a controller method.
How to with Angel