Hi there, I’m new to adonis too but I’ll answer your question just checking docs.
If it was, why would they be named it differently?
In short, Hooks are actions for database operation in a specified lifecycle event While middleware set of actions executed in sequence, one after the other in http lifecycle.
Hooks are the actions you perform before or after a specified database operation.
From very first sentence from docs.
Adonis Hooks are similar to Vue.js hooks Vue.js Lifecycle Hooks.
You can check all lifecycle events as follows:
Hooks use cases
Hashing the user password before saving it to the database.
Let’s assume, an user creates new account, after creating it, we want to send a mail to user for account verification. So we can create a hook to send email with
What Middleware can do?
Middleware can perform one/all of the following operations
- Decorate HTTP context and add values to it.
- Respond to a given request, without reaching the route action.
- Deny requests by throwing errors.
Show only authenticated users
Code blocks from docs.