Serviceberry
  • Guides
  • API Reference
  • Blog

›API Reference

Guides

  • Getting Started
  • Handlers
  • Plugins
  • Serializers and Deserializers
  • Service Tree
  • Auto Responses
  • How It Works

API Reference

  • Serviceberry
  • Trunk
  • Branch
  • Leaf
  • Request
  • Response
  • HttpError

Branch

class

Extends Leaf

A branch is created by calling method .at() on the service trunk or branch.


  • at(path[, options[, ...handlers]])
  • cope(...handlers)
  • on(options[, ...handlers])
  • on(method[, ...handlers])
  • use(...handlers)
  • waitFor(...setup)

Methods

at(path[, options[, ...handlers]])

Returns a new branch

Routes requests at a path down a new branch.

  • path string

    Paths are cumulative. Creating a new branch only requires the next piece of the path. For example, if a branch's path is "widgets" a new branch created with branch.at("{id}") will recieve a request to "widgets/42".

    Path paramaters are delimited using a pair of curly braces. Such as {id}. The branch will parse the path parameters. They are available to all handlers through request.getPathParam(name) and request.getPathParms().

  • options object [optional]

    • serializers object

      Property names must be content types such as "application/json" and values must be serializer plugins.

    • deserializers object

      Property names must be content types such as "application/json" and values must be deserializer plugins.

    • buffer boolean [optional]

      Default true

      Whether to buffer the request content. If buffer is false, the request content will be a stream instead of a string or buffer.

  • handlers function or object [optional]

    See Handlers guide.

cope(...handlers)

Returns this branch

Adds error handlers to this branch.

  • handlers function or object

    See Handlers guide.

on(options[, ...handlers])

Returns this branch

Routes requests to a new leaf. Requests that match the options will be handled by the new leaf's handlers.

  • options object
    • method string or array [optional]

      HTTP methods such as "GET", "POST", "PUT"... If not specified or is "*", all methods are matched. See nodejs.org for a list of supported methods.

    • consumes string or array [optional]

      Request content types such as "application/json", "text/csv"... If not specified all request content types are matched.

    • produces string or array [optional]

      Response content types such as "application/json", "text/csv"... If not specified all response content types are matched.

    • serializers object

      Property names must be content types such as "application/json" and values must be serializer plugins.

    • deserializers object

      Property names must be content types such as "application/json" and values must be deserializer plugins.

    • buffer boolean [optional]

      Default true

      Whether to buffer the request content. If buffer is false, the request content will be a stream instead of a string or buffer.

  • handlers function or object [optional]

    See Handlers guide.

on(method[, ...handlers])

Returns this branch

Routes requests to a new leaf. Requests that match the method will be handled by the new leaf's handlers.

  • method string or array

    HTTP methods such as "GET", "POST", "PUT"... "*" matches all methods. See nodejs.org for a list of supported methods.

  • handlers function or object [optional]

    See Handlers guide.

use(...handlers)

Returns this branch

Adds plugin handlers to this branch.

  • handlers function or object

    See Handlers guide.

waitFor(...setup)

Returns this branch

A hook for asynchronous setup tasks. The service won't be started until all asynchronous setup is complete.

  • setup promise
← TrunkLeaf →
  • Methods
    • at(path[, options[, ...handlers]])
    • cope(...handlers)
    • on(options[, ...handlers])
    • on(method[, ...handlers])
    • use(...handlers)
    • waitFor(...setup)
Guides
Getting StartedHandlersPluginsSerializers and DeserializersSerice TreeAuto ResponsesHow it Works
API Reference
ServiceberryTrunkBranchLeafReqeustResponseHttpError
More
BlogGitHubStarContributingLicense