Backstubber

module:backstubber~ Backstubber

(private) new Backstubber() → {Backstubber}

Creates a new Backstubber object.

Source:
Returns:

A new Backstubber instance.

Type
Backstubber

Methods

all(route, stub, serviceopt, statusopt) → {Backstubber}

Stubs an individual route for all HTTP verbs, optionally merging with the response from an external service. If a status code is passed, this will only stub calls that receive a matching status code from the service.

Parameters:
Name Type Attributes Description
route string

Endpoint route.

stub object

Stub definition.

service string <optional>

Service URL.

status number | string <optional>

HTTP status code, e.g. 200, 301, 3xx.

Source:
Returns:

The current Backstubber instance, for chaining.

Type
Backstubber

delete(route, stub, serviceopt, statusopt) → {Backstubber}

Stubs an individual DELETE route, optionally merging with the response from an external service. If a status code is passed, this will only stub calls that receive a matching status code from the service.

Parameters:
Name Type Attributes Description
route string

Endpoint route.

stub object

Stub definition.

service string <optional>

Service URL.

status number | string <optional>

HTTP status code, e.g. 200, 301, 3xx.

Source:
Returns:

The current Backstubber instance, for chaining.

Type
Backstubber

get(route, stub, serviceopt, statusopt) → {Backstubber}

Stubs an individual GET route, optionally merging with the response from an external service. If a status code is passed, this will only stub calls that receive a matching status code from the service.

Parameters:
Name Type Attributes Description
route string

Endpoint route.

stub object

Stub definition.

service string <optional>

Service URL.

status number | string <optional>

HTTP status code, e.g. 200, 301, 3xx.

Source:
Returns:

The current Backstubber instance, for chaining.

Type
Backstubber

Stubs an individual HEAD route, optionally merging with the response from an external service. If a status code is passed, this will only stub calls that receive a matching status code from the service.

Parameters:
Name Type Attributes Description
route string

Endpoint route.

stub object

Stub definition.

service string <optional>

Service URL.

status number | string <optional>

HTTP status code, e.g. 200, 301, 3xx.

Source:
Returns:

The current Backstubber instance, for chaining.

Type
Backstubber

listen(port, hostnameopt, backlogopt, callbackopt) → {Backstubber}

Binds and listens for connections on the specified host and port. This method is identical to Node’s http.Server.listen().

Parameters:
Name Type Attributes Default Description
port number

The port this service will listen on.

hostname string <optional>
Any IPv4 address.

The service hostname.

backlog number <optional>
511

The maximum length of the queue of pending connections.

callback function <optional>

Callback function to be called when this server starts listening.

Source:
Returns:

The current Backstubber instance, for chaining.

Type
Backstubber

mount(dir, serviceopt) → {Backstubber}

Mounts a directory containing stub definitions. Also provides optional merging with the response from an external service.

Parameters:
Name Type Attributes Description
dir string

Directory where the stubs are defined.

service string <optional>

External service URL.

Source:
Returns:

The current Backstubber instance, for chaining.

Type
Backstubber

post(route, stub, serviceopt, statusopt) → {Backstubber}

Stubs an individual POST route, optionally merging with the response from an external service. If a status code is passed, this will only stub calls that receive a matching status code from the service.

Parameters:
Name Type Attributes Description
route string

Endpoint route.

stub object

Stub definition.

service string <optional>

Service URL.

status number | string <optional>

HTTP status code, e.g. 200, 301, 3xx.

Source:
Returns:

The current Backstubber instance, for chaining.

Type
Backstubber

proxy(path, service) → {Backstubber}

Proxies all unstubbed calls to an external service.

Parameters:
Name Type Description
path string

Endpoint path, usually set to * to proxy all unhandled routes.

service string

External service URL.

Source:
Returns:

The current Backstubber instance, for chaining.

Type
Backstubber

put(route, stub, serviceopt, statusopt) → {Backstubber}

Stubs an individual PUT route, optionally merging with the response from an external service. If a status code is passed, this will only stub calls that receive a matching status code from the service.

Parameters:
Name Type Attributes Description
route string

Endpoint route.

stub object

Stub definition.

service string <optional>

Service URL.

status number | string <optional>

HTTP status code, e.g. 200, 301, 3xx.

Source:
Returns:

The current Backstubber instance, for chaining.

Type
Backstubber