Fastify multiple method in a route?

Viewed 115

In express, I can do something like this:

router.route("/").get(getController).post(postController)

How can fastify also do that?

1 Answers

The fastify does not have this chaining option, you can use multiple methods with one handler: fastify.route()

fastify.route({
  url: '/',
  method: ['GET', 'POST'],
  handler: singleController
})

// or
fastify.get('/', getController).post('/', postController)
Related