Hooks
foal generate hook my-hook
Description
Hooks are decorators that execute extra logic before and/or after the execution of a controller method.
They are particulary useful in these scenarios:
- authentication & access control
- request validation & sanitization
- logging
They improve code readability and make unit testing easier.
Built-in Hooks
Foal provides a number of hooks to handle the most common scenarios.
ValidateBody
,ValidateHeader
,ValidatePathParam
,ValidateCookie
andValidateQueryParam
validate the format of the incoming HTTP requests (see Validation).Log
displays information on the request (see Logging & Debugging).JWTRequired
,JWTOptional
,UseSessions
authenticate the user by filling thectx.user
property.PermissionRequired
restricts the route access to certain users.