Class: Application

x2node-ws~ Application

Represents the web service application.

new Application(options)

Note: The constructor is not accessible from the client code. Instances are created using module's createApplication() function.
Parameters:
Name Type Description
options module:x2node-ws~ApplicationOptions Application configuration options.
Fires:

Extends

Methods


addAuthenticator(uriPattern, authenticator)

Associate an authenticator with the specified URI pattern. When looking up authenticator for a URI, the URI patterns are matched in the order the authenticators were added to the application.
Parameters:
Name Type Description
uriPattern string URI regular expression pattern. The URI is matched against the pattern as a whole, so no starting ^ and ending $ are necessary. The match is case-sensitive.
authenticator module:x2node-ws.Authenticator The authenticator.
Returns:
This application.
Type
module:x2node-ws~Application

addAuthorizer(uriPattern, authorizer)

Associate an authorizer with the specified URI pattern. When looking up authorizer for a URI, the URI patterns are matched in the order the authorizers were added to the application.
Parameters:
Name Type Description
uriPattern string URI regular expression pattern. The URI is matched against the pattern as a whole, so no starting ^ and ending $ are necessary. The match is case-sensitive.
authorizer module:x2node-ws.Authorizer | function The authorizer. If function, the function is used as the authorizer's isAllowed() method.
Returns:
This application.
Type
module:x2node-ws~Application

addEndpoint(uriPattern, handler)

Add web service endpoint. When looking up endpoint handler for a URI, the URI patterns are matched in the order the handlers were added to the application.
Parameters:
Name Type Description
uriPattern string | Array.<string> Endpoint URI regular expression pattern. URI parameters are groups in the pattern. The URI is matched against the pattern as a whole, so no starting ^ and ending $ are necessary. The match is case-sensitive. If array, the first array element is the pattern and the rest are names for the positional URI parameters.
handler module:x2node-ws.Handler The handler for the endpoint.
Returns:
This application.
Type
module:x2node-ws~Application

addMarshaller(contentTypePattern, marshaller)

Add marshaller for the content type. When looking up marshaller for a content type, the content type patterns are matched in the order the marshallers were added to the application. After all custom marshallers are added, the application automatically adds default JSON marshaller implementation for patterns "application/json" and ".+\+json".
Parameters:
Name Type Description
contentTypePattern string Content type regular expression pattern. The content type is matched against the pattern as a whole, so no starting ^ and ending $ are necessary. It is matched without any parameters (such as charset, etc.). Also, the match is case-insensitive.
marshaller module:x2node-ws.Marshaller The marshaller implementation.
Returns:
This application.
Type
module:x2node-ws~Application

run(port)

Create HTTP server and run the application on it.
Parameters:
Name Type Description
port number Port, on which to listen for incoming HTTP requests.

setPrefix(prefix)

Set URI prefix for the subsequent addAuthenticator(), addAuthorizer() and addEndpoint() calls.
Parameters:
Name Type Description
prefix string Prefix to add to the URI patterns.
Returns:
This application.
Type
module:x2node-ws~Application

Events


shutdown

Application shutdown event. Fired after all active HTTP connections have completed.
Type: string