Module “actions”
const actions = require('@arangodb/actions')
The action module provides the infrastructure for defining low-level HTTP actions.
If you want to define HTTP endpoints in ArangoDB you should probably use the Foxx microservice framework instead.
Basics
Error message
actions.getErrorMessage(code)
Returns the error message for an error code.
Standard HTTP Result Generators
actions.defineHttp(options)
Defines a new action. The options are as follows:
options.url
The URL, which can be used to access the action. This path might containslashes. Note that this action will also be called, if a url is given such thatoptions.url is a prefix of the given url and no longer definitionmatches.
options.prefix
If false, then only use the action for exact matches. The default istrue.
options.callback(request, response)
The request argument contains a description of the request. A requestparameter foo is accessible as request.parametrs.foo. A requestheader bar is accessible as request.headers.bar. Assume thatthe action is defined for the url /foo/bar and the request url is/foo/bar/hugo/egon. Then the suffix parts [ “hugo”, “egon” ]_are availible in _request.suffix.
The callback must define fill the response.
- response.responseCode: the response code
- response.contentType: the content type of the response
- response.body: the body of the response
You can use the functions ResultOk and ResultError to easilygenerate a response.
Result ok
actions.resultOk(req, res, code, result, headers)
The function defines a response. code is the status code toreturn. result is the result object, which will be returned as JSONobject 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.
Result bad
actions.resultBad(req, res, error-code, msg, headers)
The function generates an error response.
Result not found
actions.resultNotFound(req, res, code, msg, headers)
The function generates an error response.
Result unsupported
actions.resultUnsupported(req, res, headers)
The function generates an error response.
Result error
actions.resultError(_req, *res, _code, errorNum, errorMessage, headers, keyvals)
The function generates an error response. The response body is an arraywith an attribute errorMessage containing the error messageerrorMessage, error containing true, code containingcode, errorNum containing errorNum, and errorMessage_containing the error message _errorMessage. keyvals are mixedinto the result.
Result not Implemented
actions.resultNotImplemented(req, res, msg, headers)
The function generates an error response.
Result permanent redirect
actions.resultPermanentRedirect(req, res, options, headers)
The function generates a redirect response.
Result temporary redirect
actions.resultTemporaryRedirect(req, res, options, headers)
The function generates a redirect response.
ArangoDB Result Generators
Collection not found
actions.collectionNotFound(req, res, collection, headers)
The function generates an error response.
Index not found
actions.indexNotFound(req, res, collection, index, headers)
The function generates an error response.
Result exception
actions.resultException(req, res, err, headers, verbose)
The function generates an error response. If @FA{verbose} is set totrue or not specified (the default), then the error stack trace willbe included in the error message if available. If @FA{verbose} is a stringit will be prepended before the error message and the stacktrace will alsobe included.