Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In both cases, your format is just slightly off. http:get can be used as an expression in the pre block, but the syntax is different from the way that you use it in the action block.</p> <p>There are actually a number of different ways that you could make this request. The traditional way is through a datasource</p> <p><strong>DATASOURCE</strong></p> <pre><code> global { datasource tiny_url_request &lt;- "http://tinyurl.com/api-create.php"; } rule using_datasource is active { select when pageview ".*" setting () pre { myLocation = page:env("caller"); thisTiny = datasource:tiny_url_request("?url="+myLocation); } { notify("URL", myLocation) with sticky = true; notify("datasource: ", thisTiny) with sticky = true; } } </code></pre> <p>The other way is how you were trying and it is through http:get as an expression in the pre block. Called as a function, http:get has 2 required parameters and two optional parameters: </p> <blockquote> <p>http:get(<strong>url</strong>, <strong>params</strong>, headers, response_headers );</p> </blockquote> <p>Your first attempt did not include the params.<br> tinyresponse = http:get(url2tiny)</p> <p>The second attempt places the params in the wrong argument position.<br> http:get("tinyurl.com/api-create.php";,{"url":myurl})</p> <p><strong>http:get (pre block)</strong></p> <pre><code> rule get_in_pre is active { select when pageview ".*" setting () pre { myLocation = page:env("caller"); tinyurl = http:get("http://tinyurl.com/api-create.php", {"url":myLocation}); turl = tinyurl.pick("$.content"); } { notify("http:get as expression",turl) with sticky = true; } } </code></pre> <p>The third method is using http:get as an action and auto-raising an event</p> <p><strong>http:get (action)</strong></p> <pre><code> rule using_action is active { select when pageview ".*" setting () pre { myLocation = page:env("caller"); } http:get("http://tinyurl.com/api-create.php") setting (resp) with params = {"url" : myLocation} and autoraise = "turl_event"; } rule get_event is active { select when http get label "turl_event" status_code "(\d+)" setting (code) pre { a = event:param("content"); } notify("Autoraised from action",a) with sticky = true; } </code></pre> <p>Here is an example of these rules executing against this very page <img src="https://i.stack.imgur.com/jn9bw.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload