Run
#
Run from the CLIA Deta Micro can be run directly from the deta cli
using the command deta run with an input.
In order to run a micro from the cli directly, the micro's code needs to define functions that will be run from the cli with the help of our library deta
.
The deta
library is pre-installed on a micro and can just be imported directly.
- JavaScript
- Python
With this code deployed on a micro, you can simply run
And see the following output:
#
EventsA function that is triggered from the cli must take an event
as the only argument.
You can provide an input from the cli to the function which will be passed on as an event
. It has four attributes:
event.json
:object
provides the JSON payloadevent.body
:string
provides the raw JSON payloadevent.type
:string
type of an event,run
when running from the clievent.action
:string
the action provided from the cli, defaults to an empty string
- JavaScript
- Python
With this code deployed on a micro, you can run
And should see the following output.
#
InputThe input to your function on a micro can be provided through the deta cli
and accessed in the code from the event
object. The input is a JSON object created from the arguments provided to the cli.
An important consideration is that the values in key-value pairs in the input are always either strings, list of strings or booleans.
Boolean flags are provided with a single dash, string arguments with double dash and if multiple values are provided for the same key, a list of strings will be provided.
For instance:
will provide the micro with the following input:
You need to explicitly convert the string values to other types in your code if needed.
#
ActionsActions help you run different functions based on an action
that you define for the function.
The action
defaults to an empty string if not provided.
- JavaScript
- Python
With this code deployed on a deta micro, if you run
where you tell the cli to run action hello
with "name": "deta"
as input. You should see the following output:
And if you do deta run
with action greet
you should see the following output:
#
Run and HTTPYou can combine both run and HTTP triggers in the same deta micro. For this you need to instantiate your app using the deta
library that is pre-installed on a micro.
- JavaScript
- Python
#
Run and CronYou can use both run and cron triggers in the same deta micro. You can also stack run and cron triggers for the same function.
- JavaScript
- Python