entity-routes logo
Docs

Hooks#

If you need to alter some part of the request handling, there are hooks available. These hooks are basic functions receiving arguments that will help you change or make something happens when called.

#
typescript
1type HookSchema = Partial<{
2 /**
3 * Called right after the requestContext has been set by the appropriate middleware &
4 * right before the request is handled by the response middleware
5 */
6 beforeHandle: HookFnOnHandle;
7 // Called after the request has been handled
8 afterHandle: HookFnOnHandle;
10 // Called right before the response status & body are set
11 beforeRespond: HookFnOnRespond;
12 // Called right after the response status & body are set
13 afterRespond: HookFnOnRespond;
15 // Called right before cleaning an entity from database
16 beforeClean: HookFnBeforeClean;
17 // Called right after cleaning an entity from database
18 afterClean: HookFnAfterClean;
20 // Called right before the validation of the request body
21 beforeValidate: HookFnBeforeValidate;
22 // Called right after the validation of the request body
23 afterValidate: HookFnAfterValidate;
25 // Called right before persisting payload from the request body
26 beforePersist: HookFnBeforePersist;
27 // Called right after persisting payload from the request body
28 afterPersist: HookFnAfterPersist;
30 // Called right before reading an item or a collection from database
31 beforeRead: HookFnBeforeRead;
32 // Called right after reading an item or a collection from database
33 afterRead: HookFnAfterRead;
35 // Called right before removing (or softDelete entity/unlink subresource) an entity from database
36 beforeRemove: HookFnBeforeRemove;
37 // Called right after removing (or softDelete entity/unlink subresource) an entity from database
38 afterRemove: HookFnAfterRemove;
39}>;
Prev
Middlewares
Next
Request Lifecycle