Overview
The Functions REST API is a secondary API provided by the Query service. This API enables you to manage the JavaScript libraries and objects that are used to create N1QL user-defined functions.
The API schemes and host URLs are as follows:
-
http://node:8093/
-
https://node:18093/
(for secure access)
where node
is the host name or IP address of a computer running the N1QL query engine.
Paths
Table of Contents
Read All Libraries
GET /evaluator/v1/libraries/
Responses
HTTP Code | Description | Schema |
---|---|---|
200 |
An object with multiple properties, each giving information about a single library. |
|
404 |
Not found. The path may be missing its trailing slash. |
No Content |
406 |
Not acceptable. The path may not conform to the schema. |
string |
Read a Library
GET /evaluator/v1/libraries/{library}
Responses
HTTP Code | Description | Schema |
---|---|---|
200 |
An object with a single property, giving information about the specified library. |
|
404 |
Not found. The library name in the path may be incorrect. |
string |
406 |
Not acceptable. The path may not conform to the schema. |
string |
Create or Update a Library
POST /evaluator/v1/libraries/{library}
Description
Creates the specified library and its associated functions. If the specified library exists, the existing library is overwritten.
|
Parameters
Type | Name | Description | Schema |
---|---|---|---|
Path |
library |
The name of a library. |
string |
Body |
functions |
The JavaScript code for all functions in the library. |
string |
Responses
HTTP Code | Description | Schema |
---|---|---|
200 |
The operation was successful. |
string |
400 |
Bad request. The body of the request may be incorrect. |
string |
406 |
Not acceptable. The path may not conform to the schema. |
string |
Example HTTP request
Request 3: Create or update a library called math
.
The library contains two functions, add
and sub
.
curl -X POST \
http://localhost:8093/evaluator/v1/libraries/math \
-u Administrator:password \
-H 'content-type: application/json' \
-d 'function add(a, b) { let data = a + b; return data; }
function sub(a, b) { let data = a - b; return data; }'
Request 4: Add a function called mul
to the library, leaving the other functions unchanged.
curl -X POST \
http://localhost:8093/evaluator/v1/libraries/math \
-u Administrator:password \
-H 'content-type: application/json' \
-d 'function add(a, b) { let data = a + b; return data; }
function sub(a, b) { let data = a - b; return data; }
function mul(a, b) { let data = a * b; return data; }'
Request 5: Edit the function called sub
to use a helper function called helper
, leaving the other functions unchanged.
curl -X POST \
http://localhost:8093/evaluator/v1/libraries/math \
-u Administrator:password \
-H 'content-type: application/json' \
-d 'function add(a, b) { let data = a + b; return data; }
function mul(a, b) { let data = a * b; return data; }
function sub(a, b) { return helper(a, b); }
function helper(a, b) { return a - b; }'
Request 6: Remove the function called sub
and the helper function called helper
, leaving the other functions unchanged.
curl -X POST \
http://localhost:8093/evaluator/v1/libraries/math \
-u Administrator:password \
-H 'content-type: application/json' \
-d 'function add(a, b) { let data = a + b; return data; }
function mul(a, b) { let data = a * b; return data; }'
Delete a Library
DELETE /evaluator/v1/libraries/{library}
Description
Deletes the specified library entirely.
Before you can delete a library, you must first drop all N1QL external user-defined functions which point to any of the JavaScript functions within that library. For further details, refer to DROP FUNCTION. |
Responses
HTTP Code | Description | Schema |
---|---|---|
200 |
The operation was successful. |
string |
404 |
Not found. The library name in the path may be incorrect. |
string |
406 |
Not acceptable. The path may not conform to the schema. |
string |