Skip to content


We call the primitive that returns Response as "Handler". "Middleware" is executed before and after the Handler and handles the Request and Response. It's like an onion structure.


For example, we can write the middleware to add the "X-Response-Time" header as follows.

app.use(async (c, next) => {
  const start =
  await next()
  const end =
  c.res.headers.set('X-Response-Time', `${end - start}`)

With this simple method, we can write our own custom middleware and we can use the built-in or third party middleware.

Released under the MIT License.