Contexts are a thin abstraction between http requests, Resource
s, and Script
s. They provide utility methods to simplify interacting with node's http.ServerRequest and http.ServerResponse objects.
A Context
is built from a request and response and passed to a matching Resource
by the Router
. This might originate from an external http request or a call to an internal client from a Script
.
Contexts may be created without a real request and response such as during an internal request using the dpd
object. See Internal Client for more info.
var Context = require('deployd/lib/context');
var ctx = new Context(resource, req, res, server);
Continuous callback sugar for easily calling res.end()
. Conforms to the idiomatic callback signature for most node APIs. It can be passed directly to most APIs that require a callback in node.
fs.readFile('bar.txt', ctx.done);
err
{Error | Object}An error if one occurred during handling of the ctx
. Otherwise it should be null
.
result
{Object}The result of executing the ctx
. This should be an object that is serializable as JSON.
The body of the request if sent as application/json
or application/x-www-form-urlencoded
.
The query string of the request serialized as an Object
. Supports both ?key=value
as well as ?{"key":"value"}
.
Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.
This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!