HTTP interface for user-defined AQL functions

The HTTP API for user-defined functions (UDFs) lets you add, delete, and list registered AQL extensions

AQL user functions are a means to extend the functionality of ArangoDB’s query language (AQL) with user-defined JavaScript code.

For an overview of over AQL user functions and their implications, please refer to Extending AQL.

All user functions managed through this interface are stored in the _aqlfunctions system collection. You should not modify the documents in this collection directly, but only via the dedicated interfaces.

Create a user-defined AQL function

POST /_db/{database-name}/_api/aqlfunction

Registers a user-defined function (UDF) written in JavaScript for the use in AQL queries in the current database.

In case of success, HTTP 200 is returned. If the function isn’t valid etc. HTTP 400 including a detailed error message will be returned.

Path Parameters
  • The name of the database.

Query Parameters
    HTTP Headers
      Request Body application/json object
      • a string representation of the function body.

      • an optional boolean value to indicate whether the function results are fully deterministic (function return value solely depends on the input value and return value is the same for repeated calls with same input). The isDeterministic attribute is currently not used but may be used later for optimizations.

      • the fully qualified name of the user functions.

      Responses
      • If the function already existed and was replaced by the call, the server will respond with HTTP 200.

          Response Body application/json object
        • the HTTP status code

        • boolean flag to indicate whether an error occurred (false in this case)

        • boolean flag to indicate whether the function was newly created (false in this case)

      • If the function can be registered by the server, the server will respond with HTTP 201.

          Response Body application/json object
        • the HTTP status code

        • boolean flag to indicate whether an error occurred (false in this case)

        • boolean flag to indicate whether the function was newly created (true in this case)

      • If the JSON representation is malformed or mandatory data is missing from the request, the server will respond with HTTP 400.

          Response Body application/json object
        • the HTTP status code

        • boolean flag to indicate whether an error occurred (true in this case)

        • a descriptive error message

        • the server error number

      Examples

      curl -X POST --header 'accept: application/json' --data-binary @- --dump - 'http://localhost:8529/_api/aqlfunction' <<'EOF'
      {
        "name": "myfunctions::temperature::celsiustofahrenheit",
        "code": "function (celsius) { return celsius * 1.8 + 32; }",
        "isDeterministic": true
      }
      EOF
      Show output

      Remove a user-defined AQL function

      DELETE /_db/{database-name}/_api/aqlfunction/{name}
      Deletes an existing user-defined function (UDF) or function group identified by name from the current database.
      Path Parameters
      • The name of the database.

      • the name of the AQL user function.

      Query Parameters
        • true: The function name provided in name is treated as a namespace prefix, and all functions in the specified namespace will be deleted. The returned number of deleted functions may become 0 if none matches the string.
        • false: The function name provided in name must be fully qualified, including any namespaces. If none matches the name, HTTP 404 is returned.

      HTTP Headers
        Responses
        • If the function can be removed by the server, the server will respond with HTTP 200.

            Response Body application/json object
          • the HTTP status code

          • The number of deleted user functions, always 1 when group is set to false. Any number >= 0 when group is set to true.

          • boolean flag to indicate whether an error occurred (false in this case)

        • If the user function name is malformed, the server will respond with HTTP 400.

            Response Body application/json object
          • the HTTP status code

          • boolean flag to indicate whether an error occurred (true in this case)

          • a descriptive error message

          • the server error number

        • If the specified user function does not exist, the server will respond with HTTP 404.

            Response Body application/json object
          • the HTTP status code

          • boolean flag to indicate whether an error occurred (true in this case)

          • a descriptive error message

          • the server error number

        Examples

        deletes a function:

        curl -X DELETE --header 'accept: application/json' --dump - 'http://localhost:8529/_api/aqlfunction/square::x::y'
        Show output

        function not found:

        curl -X DELETE --header 'accept: application/json' --dump - 'http://localhost:8529/_api/aqlfunction/myfunction::x::y'
        Show output

        List the registered user-defined AQL functions

        GET /_db/{database-name}/_api/aqlfunction

        Returns all registered user-defined functions (UDFs) for the use in AQL of the current database.

        The call returns a JSON array with status codes and all user functions found under result.

        Path Parameters
        • The name of the database.

        Query Parameters
        • Returns all registered AQL user functions from the specified namespace.

        HTTP Headers
          Responses
          • on success HTTP 200 is returned.

              Response Body application/json object
            • the HTTP status code

            • boolean flag to indicate whether an error occurred (false in this case)

            • All functions, or the ones matching the namespace parameter

              • A string representation of the function body

              • an optional boolean value to indicate whether the function results are fully deterministic (function return value solely depends on the input value and return value is the same for repeated calls with same input). The isDeterministic attribute is currently not used but may be used later for optimizations.

              • The fully qualified name of the user function

          • If the user function name is malformed, the server will respond with HTTP 400.

              Response Body application/json object
            • the HTTP status code

            • boolean flag to indicate whether an error occurred (true in this case)

            • a descriptive error message

            • the server error number

          Examples

          curl --header 'accept: application/json' --dump - 'http://localhost:8529/_api/aqlfunction/test'
          Show output