# Class: RoutingContext

## vertx-web-js/routing_context~ RoutingContext

#### new RoutingContext()

Represents the context for the handling of a request in Vert.x-Web.

A new instance is created for each HTTP request that is received in the

Source:
  - vertx-web-js/routing_context.js, line 42

### Methods

#### acceptableLanguages() → {Array.<LanguageHeader>}

Returns the languages for the current request. The languages are determined from the `Accept-Language` header and sorted on quality. When 2 or more entries have the same quality then the order used to return the best match is based on the lowest index on the original list. For example if a user has en-US and en-GB with same quality and this order the best match will be en-US because it was declared as first entry by the client.

Source:
  - vertx-web-js/routing_context.js, line 666

##### Returns:

The best matched language for the request

Type
  Array.<LanguageHeader>

#### acceptableLocales() → {Array.<Locale>}

Returns the locales for the current request. The locales are determined from the `accept-languages` header and sorted on quality. When 2 or more entries have the same quality then the order used to return the best match is based on the lowest index on the original list. For example if a user has en-US and en-GB with same quality and this order the best match will be en-US because it was declared as first entry by the client.

Source:
  - vertx-web-js/routing_context.js, line 644

##### Returns:

the best matched locale for the request

Type
  Array.<Locale>

#### addBodyEndHandler(handler) → {number}

Provides a handler that will be called after the last part of the body is written to the wire. The handler is called asynchronously of when the response has been received by the client. This provides a hook allowing you to do more operations once the request has been sent over the wire such as resource cleanup.

##### Parameters:

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

Source:
  - vertx-web-js/routing_context.js, line 515

##### Returns:

the id of the handler. This can be used if you later want to remove the handler.

Type
  number

#### addCookie(cookie) → {RoutingContext}

Add a cookie. This will be sent back to the client in the response. The context must have first been routed to a CookieHandler for this to work.

##### Parameters:

Name | Type | Description
--- | --- | ---
`cookie` | Cookie | the cookie

Source:
  - vertx-web-js/routing_context.js, line 248

##### Returns:

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

Type
  RoutingContext

#### addHeadersEndHandler(handler) → {number}

Add a handler that will be called just before headers are written to the response. This gives you a hook where you can write any extra headers before the response has been written when it will be too late.

##### Parameters:

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

Source:
  - vertx-web-js/routing_context.js, line 484

##### Returns:

the id of the handler. This can be used if you later want to remove the handler.

Type
  number

#### clearUser()

Clear the current user object in the context. This usually is used for implementing a log out feature, since the current user is unbounded from the routing context.

Source:
  - vertx-web-js/routing_context.js, line 595

#### cookieCount() → {number}

Source:
  - vertx-web-js/routing_context.js, line 277

##### Returns:

the number of cookies. The context must have first been routed to a CookieHandler for this to work.

Type
  number

#### cookies() → {Array.<Cookie>}

Source:
  - vertx-web-js/routing_context.js, line 290

##### Returns:

a set of all the cookies. The context must have first been routed to a CookieHandler for this to be populated.

Type
  Array.<Cookie>

#### currentRoute() → {Route}

Source:
  - vertx-web-js/routing_context.js, line 194

##### Returns:

the current route this context is being routed through.

Type
  Route

#### fail(throwable)

Fail the context with the specified throwable.

This will cause the router to route the context to any matching failure handlers for the request. If no failure handlers match a default failure response with status code 500 will be sent.

##### Parameters:

Name | Type | Description
--- | --- | ---
`throwable` | todo | a throwable representing the failure

Source:
  - vertx-web-js/routing_context.js, line 106

#### failed() → {boolean}

Source:
  - vertx-web-js/routing_context.js, line 542

##### Returns:

true if the context is being routed to failure handlers.

Type
  boolean

#### failure() → {todo}

If the context is being routed to failure handlers after a failure has been triggered by calling RoutingContext#fail then this will return that throwable. It can be used by failure handlers to render a response, e.g. create a failure response page.

Source:
  - vertx-web-js/routing_context.js, line 405

##### Returns:

the throwable used when signalling failure

Type
  todo

#### fileUploads() → {Array.<FileUpload>}

Source:
  - vertx-web-js/routing_context.js, line 359

##### Returns:

a set of fileuploads (if any) for the request. The context must have first been routed to a BodyHandler for this to work.

Type
  Array.<FileUpload>

#### get(key) → {Object}

Get some data from the context. The data is available in any handlers that receive the context.

##### Parameters:

Name | Type | Description
--- | --- | ---
`key` | string | the key for the data

Source:
  - vertx-web-js/routing_context.js, line 138

##### Returns:

the data

Type
  Object

#### getAcceptableContentType() → {string}

If the route specifies produces matches, e.g. produces `text/html` and `text/plain`, and the `accept` header matches one or more of these then this returns the most acceptable match.

Source:
  - vertx-web-js/routing_context.js, line 444

##### Returns:

the most acceptable content type.

Type
  string

#### getBody() → {Buffer}

Source:
  - vertx-web-js/routing_context.js, line 346

##### Returns:

Get the entire HTTP request body as a . The context must have first been routed to a BodyHandler for this to be populated.

Type
  Buffer

#### getBodyAsJson() → {Object}

Source:
  - vertx-web-js/routing_context.js, line 320

##### Returns:

Get the entire HTTP request body as a . The context must have first been routed to a BodyHandler for this to be populated.

Type
  Object

#### getBodyAsJsonArray() → {todo}

Source:
  - vertx-web-js/routing_context.js, line 333

##### Returns:

Get the entire HTTP request body as a . The context must have first been routed to a BodyHandler for this to be populated.

Type
  todo

#### getBodyAsString(encoding) → {string}

Get the entire HTTP request body as a string, assuming the specified encoding. The context must have first been routed to a BodyHandler for this to be populated.

##### Parameters:

Name | Type | Description
--- | --- | ---
`encoding` | string | the encoding, e.g. "UTF-16"

Source:
  - vertx-web-js/routing_context.js, line 305

##### Returns:

the body

Type
  string

#### getCookie(name) → {Cookie}

Get the cookie with the specified name. The context must have first been routed to a CookieHandler for this to work.

##### Parameters:

Name | Type | Description
--- | --- | ---
`name` | string | the cookie name

Source:
  - vertx-web-js/routing_context.js, line 233

##### Returns:

the cookie

Type
  Cookie

#### mountPoint() → {string}

Source:
  - vertx-web-js/routing_context.js, line 181

##### Returns:

the mount point for this router. It will be null for a top level router. For a sub-router it will be the path at which the subrouter was mounted.

Type
  string

#### next()

Tell the router to route this context to the next matching route (if any). This method, if called, does not need to be called during the execution of the handler, it can be called some arbitrary time later, if required.

If next is not called for a handler then the handler should make sure it ends the response or no response will be sent.

Source:
  - vertx-web-js/routing_context.js, line 90

#### normalisedPath() → {string}

Return the normalised path for the request.

The normalised path is where the URI path has been decoded, i.e. any unicode or other illegal URL characters that were encoded in the original URL with `%` will be returned to their original form. E.g. `%20` will revert to a space. Also `+` reverts to a space in a query.

The normalised path will also not contain any `..` character sequences to prevent resources being accessed outside of the permitted area.

It's recommended to always use the normalised path as opposed to if accessing server resources requested by a client.

Source:
  - vertx-web-js/routing_context.js, line 218

##### Returns:

the normalised path

Type
  string

#### parsedHeaders() → {ParsedHeaderValues}

The headers:

1. Accept
2. Accept-Charset
3. Accept-Encoding
4. Accept-Language
5. Content-Type

Parsed into ParsedHeaderValue

Source:
  - vertx-web-js/routing_context.js, line 466

##### Returns:

A container with the parsed headers.

Type
  ParsedHeaderValues

#### pathParam(name) → {string}

Gets the value of a single path parameter

##### Parameters:

Name | Type | Description
--- | --- | ---
`name` | string | the name of parameter as defined in path declaration

Source:
  - vertx-web-js/routing_context.js, line 733

##### Returns:

the actual value of the parameter or null if it doesn't exist

Type
  string

#### pathParams() → {Array.<string>}

Returns a map of named parameters as defined in path declaration with their actual values

Source:
  - vertx-web-js/routing_context.js, line 719

##### Returns:

the map of named parameters

Type
  Array.<string>

#### preferredLanguage() → {LanguageHeader}

Helper to return the user preferred language. It is the same action as returning the first element of the acceptable languages.

Source:
  - vertx-web-js/routing_context.js, line 702

##### Returns:

the users preferred locale.

Type
  LanguageHeader

#### preferredLocale() → {Locale}

Helper to return the user preferred locale. It is the same action as returning the first element of the acceptable locales.

Source:
  - vertx-web-js/routing_context.js, line 684

##### Returns:

the users preferred locale.

Type
  Locale

#### put(key, obj) → {RoutingContext}

Put some arbitrary data in the context. This will be available in any handlers that receive the context.

##### Parameters:

Name | Type | Description
--- | --- | ---
`key` | string | the key for the data
`obj` | Object | the data

Source:
  - vertx-web-js/routing_context.js, line 123

##### Returns:

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

Type
  RoutingContext

#### remove(key) → {Object}

Remove some data from the context. The data is available in any handlers that receive the context.

##### Parameters:

Name | Type | Description
--- | --- | ---
`key` | string | the key for the data

Source:
  - vertx-web-js/routing_context.js, line 152

##### Returns:

the previous data associated with the key

Type
  Object

#### removeBodyEndHandler(handlerID) → {boolean}

Remove a body end handler

##### Parameters:

Name | Type | Description
--- | --- | ---
`handlerID` | number | the id as returned from RoutingContext#addBodyEndHandler.

Source:
  - vertx-web-js/routing_context.js, line 529

##### Returns:

true if the handler existed and was removed, false otherwise

Type
  boolean

#### removeCookie(name) → {Cookie}

Remove a cookie. The context must have first been routed to a CookieHandler for this to work.

##### Parameters:

Name | Type | Description
--- | --- | ---
`name` | string | the name of the cookie

Source:
  - vertx-web-js/routing_context.js, line 264

##### Returns:

the cookie, if it existed, or null

Type
  Cookie

#### removeHeadersEndHandler(handlerID) → {boolean}

Remove a headers end handler

##### Parameters:

Name | Type | Description
--- | --- | ---
`handlerID` | number | the id as returned from RoutingContext#addHeadersEndHandler.

Source:
  - vertx-web-js/routing_context.js, line 498

##### Returns:

true if the handler existed and was removed, false otherwise

Type
  boolean

#### request() → {HttpServerRequest}

Source:
  - vertx-web-js/routing_context.js, line 53

##### Returns:

the HTTP request object

Type
  HttpServerRequest

#### reroute(method, path)

Restarts the current router with a new method and path. All path parameters are then parsed and available on the params list.

##### Parameters:

Name | Type | Description
--- | --- | ---
`method` | Object | the new http request
`path` | string | the new http path.

Source:
  - vertx-web-js/routing_context.js, line 623

#### response() → {HttpServerResponse}

Source:
  - vertx-web-js/routing_context.js, line 69

##### Returns:

the HTTP response object

Type
  HttpServerResponse

#### session() → {Session}

Get the session. The context must have first been routed to a SessionHandler for this to be populated. Sessions live for a browser session, and are maintained by session cookies.

Source:
  - vertx-web-js/routing_context.js, line 375

##### Returns:

the session.

Type
  Session

#### setAcceptableContentType(contentType)

Set the acceptable content type. Used by

##### Parameters:

Name | Type | Description
--- | --- | ---
`contentType` | string | the content type

Source:
  - vertx-web-js/routing_context.js, line 608

#### setBody(body)

Set the body. Used by the BodyHandler. You will not normally call this method.

##### Parameters:

Name | Type | Description
--- | --- | ---
`body` | Buffer | the body

Source:
  - vertx-web-js/routing_context.js, line 555

#### setSession(session)

Set the session. Used by the SessionHandler. You will not normally call this method.

##### Parameters:

Name | Type | Description
--- | --- | ---
`session` | Session | the session

Source:
  - vertx-web-js/routing_context.js, line 568

#### setUser(user)

Set the user. Usually used by auth handlers to inject a User. You will not normally call this method.

##### Parameters:

Name | Type | Description
--- | --- | ---
`user` | User | the user

Source:
  - vertx-web-js/routing_context.js, line 581

#### statusCode() → {number}

If the context is being routed to failure handlers after a failure has been triggered by calling RoutingContext#fail then this will return that status code. It can be used by failure handlers to render a response, e.g. create a failure response page. When the status code has not been set yet (it is undefined) its value will be -1.

Source:
  - vertx-web-js/routing_context.js, line 426

##### Returns:

the status code used when signalling failure

Type
  number

#### user() → {User}

Get the authenticated user (if any). This will usually be injected by an auth handler if authentication if successful.

Source:
  - vertx-web-js/routing_context.js, line 389

##### Returns:

the user, or null if the current user is not authenticated.

Type
  User

#### vertx() → {Vertx}

Source:
  - vertx-web-js/routing_context.js, line 165

##### Returns:

the Vert.x instance associated to the initiating Router for this context

Type
  Vertx