@@ -44,19 +44,31 @@ data type.
44
44
## Invoking modules
45
45
46
46
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:
49
59
50
60
```
51
61
# Set the input to the URI of the module you wish to invoke in your application's
52
62
# modules database.
53
- client.invoke("/path/to/module .sjs")
63
+ client.invoke("/sample .sjs")
54
64
```
55
65
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):
57
69
58
70
```
59
- client.invoke("/path/to/module .sjs", vars={"my_var1": "value1"})
71
+ client.invoke("/sample .sjs", vars={"my_var1": "value1"})
60
72
```
61
73
62
74
## Conversion of data types
0 commit comments