Table of Contents generated with DocToc
Requiring the server returns back a function ready to be inserted into Hapi's .plugin()
method.
The bridge plugin will instantiate a Toki Core and provide it a server object for hooking up routes.
route({
method: 'GET',
path: '/my/url/here',
handler: (request, response) => {...}
});
+ `GET`
+ `POST`
+ `PUT`
+ `DEL`
+ `PATCH`
Any string. Parameterization is allowed.
A function which accepts a Request and a Response object
These are convenience methods for the route() function above.
get('/my/path', (request, response) => {...})
The server object inherits from EventEmitter and emits the following events:
- start - When the server is started
- stop - When the server is stopped
Request is a decorated version of the Node http-server request object. It will always have the following:
request.query
- a parsed query objectrequest.params
- an object of any params from pathsrequest.path
- the current pathrequest.method
- the method which called this requestrequest.headers
- an object containing all headersrequest.rawRequest
- The raw, underlying request object. This is guaranteed to be a readableStream. It may or may not be an instance of http.IncomingMessage.
Response is an object which allows you to send data back to the client as well as set status codes, headers and return errors.
response.send(payload)
where payload is a string, an object or a promise. If payload is an instance of error, it'll be sent to response.error().response.error(error)
where payload is an instance of error will send back a default status code as well as show the error.response.statusCode(status)
where status is a number will send back that statusCode. It can be called before or after send().response.header(name, value)
will set the named header to the new value. It can be called before or after send().response.rawResponse
is the raw underlying Response object. This is guaranteed to be a writableStream. It may or may not be an instance of http.ServerResponse.