Skip to main content
Go to Latest
File

hooks

Hooks are functions that allow you to extend the functionality of a route and reuse functions throughout your app without having to write the same code over and over again.

preValidator

The preValidator hook is triggered prior to any validation. If you modify the body of the response in this function, all subsequent hooks including your handler get skipped.

import { Get } from 'darkflare'

Get({
  preValidator(c) {
    ...
  }
}, c => {
  ...
})

postValidator

This hook gets fired after the request got validated by your schema.

import { Get } from 'darkflare'

Get({
  postValidator(c) {
    ...
  }
}, c => {
  ...
})

preHandler

This hook will fire after the postValidator hook. (only if you didn’t modify the response body beforehand)

import { Get } from 'darkflare'

Get({
  preHandler(c) {
    ...
  }
}, c => {
  ...
})

postHandler

This hook will fire after your actual handler ran. It will always fire - even if you already set a response body before. This hook is meant for attaching e.g. a header and not for modifying the body of the response.

import { Get } from 'darkflare'

Get({
  postHandler(c) {
    ...
  }
}, c => {
  ...
})