ArangoDB

Module "actions"

The action module provides the infrastructure for defining HTTP actions.


  1. Basics
    1. actions.defineHttp
    2. actions.resultError
    3. actions.getErrorMessage
  2. Standard HTTP Result Generators
    1. actions.resultOK
    2. actions.resultBad
    3. actions.resultNotFound
    4. actions.resultUnsupported
  3. ArangoDB Result Generators
    1. actions.collectionNotFound
    2. actions.indexNotFound
    3. actions.resultException

Basics


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 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 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 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)
The functions generates an error response. The response body is an array with an attribute 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)
Returns the error message for an error code.


Standard HTTP Result Generators


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)
The functions generates an error response.



actions.resultNotFound(req, res, msg, headers)
The functions generates an error response.



actions.resultUnsupported(req, res, headers)
The functions generates an error response.


ArangoDB Result Generators


actions.collectionNotFound(req, res, collection, headers)
The functions generates an error response.



actions.collectionNotFound(req, res, collection, index, headers)
The functions generates an error response.



actions.resultException(req, res, err, headers)
The functions generates an error response.