Serviceberry
object
When you require "serviceberry" this is the object that you receive. The most important property is the factory function createTrunk(). It is the entry point of the framework.
A service is created by creating a trunk then branches and leaves are added using .at() and .on(). Each branch can have it's own branches and leaves allowing plugins and error handlers to be added at any levels with methods .use() and .cope() on the trunk or any branch or leaf.
Properties
createTrunk([options])
Creating a trunk using this factory function is the first thing you'll do when creating a service. This is the entry point of the framework.
const service = serviceberry.createTrunk({
port: 3000,
basePath: "api",
callback: () => console.log("Sevice started!")
});
- options object [optional]
autoStart boolean [optional]
Default true
If false, the service won't begin handling requests until .start() is called.
backlog number [optional]
Default 511
Maximum number of queued pending connections. See nodejs.org.
callback function [optional]
Listener for server's listening event.
deserializers object [optional]
Property names must be content types such as "application/json" and values must be deserializer handlers.
When requests need deserialized, a deserializer matching the request's content type will be used.
host string [optional]
Default all hosts
The host to listen on. See nodejs.org.
path string [optional]
Default empty string
Base path of the trunk. All request handled by the service must begin with this path.
port number [optional]
Default 3000
The port to listen on. See nodejs.org.
serializers object [optional]
Property names must be content types such as "application/json" and values must be serializer handlers.
When responses need serialized, a serializer matching the response's content type will be used.
timeout number [optional]
Default 10000
Number of milliseconds to wait before aborting requests.
HttpError
A class for creating HTTP specific error objects. It isn't strictly necessary for creating Serviceberry services. It is here for your convenience.
The HttpError constructor has the same arguments signature as request.fail() and is instanced internally by Serviceberry when a request fails. HttpError instances are the error objects available at request.error inside of error handlers.
statusCodes
This is a helper for avoiding magic numbers and helping your services and plugins be more legible. It isn't strictly necessary for creating Serviceberry services. It is here for your convenience.
It includes all the statuses in Node.js's http.STATUS_CODES. It has status codes as properties at constant case status names such as statusCodes.OK and status codes as properties at status text names such as statusCode["Not Found"].