Response to webhook event with raw data

I would like to write a rule set that can respond to web host events using raw data. An event may appear from a URL, for example:

http://cs.kobj.net/blue/event/rest/echo/a163x85/?a163x85:kynetx_app_version=dev&body=hi%20there 

I can use the send_directive() action, but this returns a lot of JSON, which I don't necessarily need:

 // KNS Fri Apr 8 19:40:40 2011 {"directives":[{"options":{"body":"hi there"},"name":"echo","meta":{"rule_name":"echo","txn_id":"154CEDCC-6218-11E0-9E71-726A5E50CE3F","rid":"a163x85"}}]} 

Is there a way to respond only to raw data, and not to an entire directory structure?

+4
source share
1 answer

The answer is to use a Webhook endpoint to communicate with KNS, rather than directly signaling an event.

You will signal your event like this:

http://webhooks.kynetxapps.net/h/a163x85.dev/echo?body=hi%20there

And such a rule:

 rule x { select when webhook echo pre { body = event:param("body"); response = { 'thebody': body }; rjson = response.encode(); } send_directive("json") with body = rjson; } 

For an answer like:

 {"thebody":"hi there"} 

Note the .dev in the URL to indicate the dev version of the application, echo as the name of the event and the domain of the webhook event.

The endpoint will even serve it with the appropriate json type / type.

Also note that you can return html, xml, js, plain text, and even redirects. For more information, see Webhook Endpoint Documents .

+2
source

Source: https://habr.com/ru/post/1347298/


All Articles