The action module provides the infrastructure for defining HTTP actions.
actions.defineHttp(options)
options.url
The URL, which can be used to access the action. This path might contain slashes. Note that this action will also be called, if a url is given such that options.url is a prefix of the given url and no longer definition matches.
options.prefix
If false
, then only use the action for excat matches. The default is true
.
options.context
The context to which this actions belongs. Possible values are "admin", "monitoring", "api", and "user". All contexts apart from "user" are reserved for system actions and are database independent. All actions except "user" and "api" are executed in a different worker queue than the normal queue for clients. The "api" actions are used by the client api to communicate with the ArangoDB server. Both the "api" and "user" actions are using the same worker queue.
It is possible to specify a list of contexts, in case an actions belongs to more than one context.
Note that the url for "user" actions is automatically prefixed with _action
. This applies to all specified contexts. For example, if the context contains "admin" and "user" and the url is hallo
, then the action is accessible under /_action/hallo
- even for the admin context.
options.callback(request, response)
The request argument contains a description of the request. A request parameter foo
is accessible as request.parametrs.foo
. A request header bar
is accessible as request.headers.bar
. Assume that the action is defined for the url /foo/bar
and the request url is /foo/bar/hugo/egon
. Then the suffix parts [ "hugon", "egon" ]
are availible in request.suffix
.
The callback must define fill the response.
response.responseCode
: the response coderesponse.contentType
: the content type of the responseresponse.body
: the body of the responseYou can use the functions ResultOk
and ResultError
to easily generate a response.
options.parameters
Normally the parameters are passed to the callback as strings. You can use the options, to force a converstion of the parameter to
"collection"
"collection-identifier"
"collection-name"
"number"
"string"
actions.resultError(req, res, code, errorNum, errorMessage, headers, keyvals)
errorMessage
containing the error message errorMessage, error
containing true
, code
containing code, errorNum
containing errorNum, and errorMessage
containing the error message errorMessage. keyvals are mixed into the result.
actions.getErrorMessage(code)
actions.resultOk(req, res, code, result, headers
The functions defines a response. code is the status code to return. result is the result object, which will be returned as JSON object in the body. headers
is an array of headers to returned. The function adds the attribute error
with value false
and code
with value code to the result.
actions.resultBad(req, res, error-code, msg, headers)
actions.resultNotFound(req, res, msg, headers)
actions.resultUnsupported(req, res, headers)
actions.collectionNotFound(req, res, collection, headers)
actions.collectionNotFound(req, res, collection, index, headers)
actions.resultException(req, res, err, headers)