# Class: Router

## vertx-web-js/router~ Router

#### new Router()

  Source:
    - router.js, line 31

### Methods

#### accept(request)

  This method is used to provide a request to the router. Usually you take request from the HttpServer#requestHandler and pass it to this method. The router then routes it to matching routes.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `request` | HttpServerRequest | the request

  Source:
    - router.js, line 44

#### clear() → {Router}

  Remove all the routes from this router
  Source:
    - router.js, line 378

  ##### Returns:

  a reference to this, so the API can be used fluently
  Type
    Router

#### connect(path) → {Route}

  Add a route that matches a HTTP CONNECT request and the specified path

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `path` | string | URI paths that begin with this path will match

  Source:
    - router.js, line 304

  ##### Returns:

  the route
  Type
    Route

#### connectWithRegex(regex) → {Route}

  Add a route that matches a HTTP CONNECT request and the specified path regex

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `regex` | string | URI paths that begin with a match for this regex will match

  Source:
    - router.js, line 320

  ##### Returns:

  the route
  Type
    Route

#### delete(path) → {Route}

  Add a route that matches a HTTP DELETE request and the specified path

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `path` | string | URI paths that begin with this path will match

  Source:
    - router.js, line 244

  ##### Returns:

  the route
  Type
    Route

#### deleteWithRegex(regex) → {Route}

  Add a route that matches a HTTP DELETE request and the specified path regex

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `regex` | string | URI paths that begin with a match for this regex will match

  Source:
    - router.js, line 260

  ##### Returns:

  the route
  Type
    Route

#### exceptionHandler(exceptionHandler) → {Router}

  Specify a handler for any unhandled exceptions on this router. The handler will be called for exceptions thrown from handlers. This does not affect the normal failure routing logic.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `exceptionHandler` | function | the exception handler

  Source:
    - router.js, line 410

  ##### Returns:

  a reference to this, so the API can be used fluently
  Type
    Router

#### get(path) → {Route}

  Add a route that matches a HTTP GET request and the specified path

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `path` | string | URI paths that begin with this path will match

  Source:
    - router.js, line 94

  ##### Returns:

  the route
  Type
    Route

#### getRoutes() → {Array.<Route>}

  Source:
    - router.js, line 364

  ##### Returns:

  - a list of all the routes on this router
  - Type
      Array.<Route>

#### getWithRegex(regex) → {Route}

  Add a route that matches a HTTP GET request and the specified path regex

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `regex` | string | URI paths that begin with a match for this regex will match

  Source:
    - router.js, line 110

  ##### Returns:

  the route
  Type
    Route

#### handleContext(context)

  Used to route a context to the router. Used for sub-routers. You wouldn't normally call this method directly.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `context` | RoutingContext | the routing context

  Source:
    - router.js, line 426

#### handleFailure(context)

  Used to route a failure to the router. Used for sub-routers. You wouldn't normally call this method directly.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `context` | RoutingContext | the routing context

  Source:
    - router.js, line 439

#### head(path) → {Route}

  Add a route that matches a HTTP HEAD request and the specified path

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `path` | string | URI paths that begin with this path will match

  Source:
    - router.js, line 124

  ##### Returns:

  the route
  Type
    Route

#### headWithRegex(regex) → {Route}

  Add a route that matches a HTTP HEAD request and the specified path regex

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `regex` | string | URI paths that begin with a match for this regex will match

  Source:
    - router.js, line 140

  ##### Returns:

  the route
  Type
    Route

#### mountSubRouter(mountPoint, subRouter) → {Router}

  Mount a sub router on this router

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `mountPoint` | string | the mount point (path prefix) to mount it on
  `subRouter` | Router | the router to mount as a sub router

  Source:
    - router.js, line 394

  ##### Returns:

  a reference to this, so the API can be used fluently
  Type
    Router

#### options(path) → {Route}

  Add a route that matches a HTTP OPTIONS request and the specified path

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `path` | string | URI paths that begin with this path will match

  Source:
    - router.js, line 154

  ##### Returns:

  the route
  Type
    Route

#### optionsWithRegex(regex) → {Route}

  Add a route that matches a HTTP OPTIONS request and the specified path regex

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `regex` | string | URI paths that begin with a match for this regex will match

  Source:
    - router.js, line 170

  ##### Returns:

  the route
  Type
    Route

#### patch(path) → {Route}

  Add a route that matches a HTTP PATCH request and the specified path

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `path` | string | URI paths that begin with this path will match

  Source:
    - router.js, line 334

  ##### Returns:

  the route
  Type
    Route

#### patchWithRegex(regex) → {Route}

  Add a route that matches a HTTP PATCH request and the specified path regex

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `regex` | string | URI paths that begin with a match for this regex will match

  Source:
    - router.js, line 350

  ##### Returns:

  the route
  Type
    Route

#### post(path) → {Route}

  Add a route that matches a HTTP POST request and the specified path

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `path` | string | URI paths that begin with this path will match

  Source:
    - router.js, line 214

  ##### Returns:

  the route
  Type
    Route

#### postWithRegex(regex) → {Route}

  Add a route that matches a HTTP POST request and the specified path regex

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `regex` | string | URI paths that begin with a match for this regex will match

  Source:
    - router.js, line 230

  ##### Returns:

  the route
  Type
    Route

#### put(path) → {Route}

  Add a route that matches a HTTP PUT request and the specified path

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `path` | string | URI paths that begin with this path will match

  Source:
    - router.js, line 184

  ##### Returns:

  the route
  Type
    Route

#### putWithRegex(regex) → {Route}

  Add a route that matches a HTTP PUT request and the specified path regex

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `regex` | string | URI paths that begin with a match for this regex will match

  Source:
    - router.js, line 200

  ##### Returns:

  the route
  Type
    Route

#### route(method, path) → {Route}

  Add a route that matches the specified HTTP method and path

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `method` | Object | the HTTP method to match
  `path` | string | URI paths that begin with this path will match

  Source:
    - router.js, line 59

  ##### Returns:

  the route
  Type
    Route

#### routeWithRegex(method, regex) → {Route}

  Add a route that matches the specified HTTP method and path regex

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `method` | Object | the HTTP method to match
  `regex` | string | URI paths that begin with a match for this regex will match

  Source:
    - router.js, line 78

  ##### Returns:

  the route
  Type
    Route

#### trace(path) → {Route}

  Add a route that matches a HTTP TRACE request and the specified path

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `path` | string | URI paths that begin with this path will match

  Source:
    - router.js, line 274

  ##### Returns:

  the route
  Type
    Route

#### traceWithRegex(regex) → {Route}

  Add a route that matches a HTTP TRACE request and the specified path regex

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `regex` | string | URI paths that begin with a match for this regex will match

  Source:
    - router.js, line 290

  ##### Returns:

  the route
  Type
    Route