Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Info

send_javascript and send_raw are not yet available.

Taking action is the primary reason for executing rules. Ironically, the basis for this most basic and important part of KRL is surprisingly simple. There are just a few fundamental actions. The rest are built from these .

Before I describe the specific actions, you need to understand the structure of actions. Like functions, actions have a name and a set of parameters. Unnamed parameters are specified first, in order, followed by a list of name-value pairs in any order. The name and value are paired using an equal sign (=):

Code Block
languagejavascript
themeConfluence
foo("hello", 5, x = "world", y = 6 + 5)

This action has a name, foo, and two unnamed parameters, "hello" and 5. The action also has two named parameters, x with the value "world" and y with the value 11. The parameters, named and unnamed, can be any valid KRL expression and will be evaluated prior to the action being taken. More formally, parameters are evaluated in applicative order.

The following as user-defined actions.

The following are the most commonly used basic actions are available in KRL:

...

See the send_directive() documentation for more details. 

send_javascript(<expr>). This returns its argument as a JavaScript closure application whose body is given by <expr>. The names of any optional parameters are used as parameters in the closure. The closure is applied to the values of any optional parameters. This action is used for communicating with browser endpoints. For example, the following action produces the JavaScript below it. (The <|...|> syntax, called clown hats, is a type of KRL extended quote for producing JavaScript. Values in clown hats are assumed to be JavaScript. White space is not necessarily preserved and templating mechanisms are available.)

Code Block
languagejavascript
themeConfluence
send_javascript(<|x + y|>) with
  x = 5 and
  y = 6 

(function(x, y) { x + y } (5, 6));


http:post(<expr>). This action makes an HTTP POST to the URL given by <expr>. Any parameters in the optional qs map are added as name-value pairs in the query string of the URL. This action is useful for interacting with external Web services. For example, the following action makes an HTTP POST to the given URL, form-encoding q and sending it as the body of the POST:

Code Block
languagejavascript
themeConfluence
http:post("http://google.com/search", qs = {"q":"hello"})

send_raw(<type>). This returns raw content. This is especially useful for returning content with a mime-type different from application/json or returning raw JSON without the enclosing directive. See the send_raw() documentation for more information. 

(Classic) Web Actions discusses actions that are specific to the Web. See the HTTP module documentation for more information. 

event:send(<expr>). This action sends an event to another pico. The event channel of the other pico is specified in a map with the name "cid" (channel ID). The action also takes a domain and type for the event to send.  You can specify event attributes using the optional with clause:

Code Block
languagejavascript
themeConfluence
event:send({"cid": owner}, "fuse", event:type())
     with attrs = event:attrs();

For details about how this works, see the documentation for the event library

See also User Defined Actions and Compound Actions.