webservices
A web-service is a function that can be called outside of Marjory
The webservices
directory contains your web-services functions. Marjory reads all the .js
files inside this directory and automatically creates the web-services for you.
A web-service is and exported function that exists inside of the webservices
folder. You do not have to write only one web-service per file, but we recommend doing so as it will keep your code clean.
If you do not export your function, it will not be defined as a web-service
Properties
data
The property data contains all the inputs of a web-service. To know more about prescript, see How to add and configure a service action
Here is an example of a marjory.yml
web-service section and the object you can work with in a web-service function:
credentials
The property credentials
contains all the credentials information defined when the module was installed by someone. The list of given credentials are defined in the marjory.yml
file.
Here is an example of a marjory.yml
credentials section and the object you can work with in a web-service function:
SDK
ModuleResponse
ModuleResponse is a simple class allowing you to return data (object or basic type) to user calling the web-service. This will return an object with the data passed and a status code of 200.
ModuleError
ModuleError is to handle your web-service errors, it's like an HTTP error. Here is an example:
If no pancake is found, this will return an object with a 404 status code and a data object containing the message.
Storage
You might need to keep storage between multiple action execution for the same operator. You can do so by using the DB object of the SDK.
Here is all the functions you can use on the DB object:
Do not use const { DB } = Marjory
from outside your function
Behind the DB object is a MongoDB instance. You can learn more on how to use these functions directly from mongo documentation.
Last updated