Skip to main content

Router

Class that specifies used middlewares.

Methods

See: RequestHandler

router.use(arg1: string | RequestHandler | Router, arg2?: RequestHandler | Router): Router

Overloads

router.use(handler: RequestHandler): Router

router.use(router: Router): Router

router.use(path: string, handler: RequestHandler): Router

router.use(path: string, router: Router): Router

  • path: string - request path
  • handler: RequestHandler | Router - request handler function or a router

Adds middleware that matches any request method.

router.get(arg1: string | RequestHandler | Router, arg2?: RequestHandler | Router): Router

Overloads

router.get(handler: RequestHandler): Router

router.get(router: Router): Router

router.get(path: string, handler: RequestHandler): Router

router.get(path: string, router: Router): Router

  • path: string - request path
  • handler: RequestHandler | Router - request handler function or a router

Adds middleware that matches GET request method.

router.post(arg1: string | RequestHandler | Router, arg2?: RequestHandler | Router): Router

Overloads

router.post(handler: RequestHandler): Router

router.post(router: Router): Router

router.post(path: string, handler: RequestHandler): Router

router.post(path: string, router: Router): Router

  • path: string - request path
  • handler: RequestHandler | Router - request handler function or a router

Adds middleware that matches POST request method.

router.put(arg1: string | RequestHandler | Router, arg2?: RequestHandler | Router): Router

Overloads

router.put(handler: RequestHandler): Router

router.put(router: Router): Router

router.put(path: string, handler: RequestHandler): Router

router.put(path: string, router: Router): Router

  • path: string - request path
  • handler: RequestHandler | Router - request handler function or a router

Adds middleware that matches PUT method.

router.delete(arg1: string | RequestHandler | Router, arg2?: RequestHandler | Router): Router

Overloads

router.delete(handler: RequestHandler): Router

router.delete(router: Router): Router

router.delete(path: string, handler: RequestHandler): Router

router.delete(path: string, router: Router): Router

  • path: string - request path
  • handler: RequestHandler | Router - request handler function or a router

Adds middleware that matches DELETE method.

router.connect(arg1: string | RequestHandler | Router, arg2?: RequestHandler | Router): Router

Overloads

router.connect(handler: RequestHandler): Router

router.connect(router: Router): Router

router.connect(path: string, handler: RequestHandler): Router

router.connect(path: string, router: Router): Router

  • path: string - request path
  • handler: RequestHandler | Router - request handler function or a router

Adds middleware that matches CONNECT method. Note that this method can have more complex implementation than other Router methods. For more details, see CONNECT HTTP method.

router.options(arg1: string | RequestHandler | Router, arg2?: RequestHandler | Router): Router

Overloads

router.options(handler: RequestHandler): Router

router.options(router: Router): Router

router.options(path: string, handler: RequestHandler): Router

router.options(path: string, router: Router): Router

  • path: string - request path
  • handler: RequestHandler | Router - request handler function or a router

Adds middleware that matches OPTIONS method.

router.trace(arg1: string | RequestHandler | Router, arg2?: RequestHandler | Router): Router

Overloads

router.trace(handler: RequestHandler): Router

router.trace(router: Router): Router

router.trace(path: string, handler: RequestHandler): Router

router.trace(path: string, router: Router): Router

  • path: string - request path
  • handler: RequestHandler | Router - request handler function or a router

Adds middleware that matches TRACE method.

router.patch(arg1: string | RequestHandler | Router, arg2?: RequestHandler | Router): Router

Overloads

router.patch(handler: RequestHandler): Router

router.patch(router: Router): Router

router.patch(path: string, handler: RequestHandler): Router

router.patch(path: string, router: Router): Router

  • path: string - request path
  • handler: RequestHandler | Router - request handler function or a router

Adds middleware that matches PATCH method.