As we have already mentioned, a controller function is a function the router calls when a request comes in and addresses a particular path. It can look this simple:
router.get("hello") { req in return "Hello, world." }
We can, of course, specify more than just that. Here are some examples:
router.post("hello", use: myPostFunction)
router.patch("hello", use: controllerClass.helloPatch)
You can see that we only need to specify a function for the router that can be called and that returns a ResponseEncodable object.
A lot of other classes can be made to conform to the ResponseEncodable protocol. A simple string, for example, is extended to be a valid return – just like in the preceding case.
Technically, we do not need controller classes because the router only needs functions. Controller classes are, however, a...