Skip to content

Commit 8f310a0

Browse files
authored
Merge pull request #53 from marklogic/feature/invoke-tweak
Added example module to invoke
2 parents 0c38fe3 + d132aa6 commit 8f310a0

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

docs/eval.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,31 @@ data type.
4444
## Invoking modules
4545

4646
The [v1/invoke REST endpoint](https://docs.marklogic.com/REST/POST/v1/invoke) supports the execution of JavaScript
47-
and XQuery main modules that have been deployed to your application's modules database. A module can be invoked via
48-
the client in the following manner:
47+
and XQuery main modules that have been deployed to your application's modules database.
48+
49+
If you wish to attempt the examples below (instead of invoking your own modules), first run the following to
50+
insert a simple runnable module into the out-of-the-box "Modules" database:
51+
52+
```
53+
from marklogic.documents import Document
54+
module = Document('/sample.sjs', 'const doc = {"hello": "world"}; doc', permissions={"rest-reader": ["read", "update", "execute"]})
55+
client.documents.write(module, params={"database": "Modules"})
56+
```
57+
58+
A module can be invoked via the client in the following manner:
4959

5060
```
5161
# Set the input to the URI of the module you wish to invoke in your application's
5262
# modules database.
53-
client.invoke("/path/to/module.sjs")
63+
client.invoke("/sample.sjs")
5464
```
5565

56-
You can provide variables to your module in the same fashion as when evaluating custom code:
66+
You can provide variables to your module in the same fashion as when evaluating custom
67+
code (the variable will not have any impact on the sample module loaded above; this is
68+
shown purely to demonstrate how to define variables):
5769

5870
```
59-
client.invoke("/path/to/module.sjs", vars={"my_var1": "value1"})
71+
client.invoke("/sample.sjs", vars={"my_var1": "value1"})
6072
```
6173

6274
## Conversion of data types

0 commit comments

Comments
 (0)