New Pipelines Transformer: Webhook

A new Pipelines transformer for calling an external webhook for data transformation is now generally available for Golioth users. The webhook transformer, not be confused with the webhook data destination, dramatically expands the capabilities of Pipelines by enabling users to target any existing public API or perform arbitrary data transformations by writing their own code.

Note: Egress data when using the webhook transformers incurs usage. See Golioth’s pricing options for more information on costs and our generous free tier.

How It Works

The webhook transformer accepts data of any content type, and sends it to the specified URL as an HTTP POST request. The response replaces the outgoing data, allowing it to be passed through further transformers, before being delivered to one or more data destinations.

filter:
  path: "*"
  filter: application/cbor
steps:
  - name: convert-json
    transformer:
      type: cbor-to-json
  - name: external-transform
    transformer:
      type: webhook
      parameters:
        url: https://temp-converter.golioth.workers.dev/
  - name: send-lightdb-stream
    destination:
      type: lightdb-stream
      version: v1

Click here to use this pipeline in your Golioth project!

In the pipeline above, the webhook transformer is used to target a Cloudflare Worker that converts temperature data from Celsius to Fahrenheit. CBOR encoded device data arrives at the pipeline, then is converted to JSON and delivered to the webhook transformer. The worker is a minimal JavaScript function that checks if a temp field is present in the JSON data, and if so, converts it.

export default {
    async fetch(request) {
        const body = await request.json();
        if (body.temp) {
            body.temp = body.temp * 9 / 5 + 32
        }
        return Response.json(body, { status: 200 });
    },
};

Finally, data is delivered to LightDB Stream, where it can be observed in the Golioth console. In the following example, CBOR payloads that included a temp field with values 34.5 and 32 respectively arrived at the pipeline. Each had their temp value converted from Celsius to Fahrenheit.

Temperature converted from Celsius to Fahrenheit in LightDB Stream

For more information on the webhook transformer, go to the documentation.

What’s Next

This post details one of the simplest cases of using the webhook transformer, but the possibilities it enables are endless. Keep an eye out for more examples on the blog next week, and let us know how you are using Golioth Pipelines on the forum!

Dan Mangum
Dan Mangum
Dan is an experienced engineering leader, having built products and teams at both large companies and small startups. He has a history of leadership in open source communities, and has worked across many layers of the technical stack, giving him unique insight into the constraints faced by Golioth’s customers and the requirements of a platform that enables their success.

Post Comments

No comments yet! Start the discussion at forum.golioth.io

More from this author

Related posts

spot_img

Latest posts

Useful Zephyr Shells for IoT Development

The Zephyr shell subsystem will help you directly interact with and troubleshoot your IoT hardware. This post details our most commonly used commands, as well as a listing of all Zephyr shell modules that we could extract from a recent project.

Guide to Securely Store Credentials on an nRF91 Modem

The Nordic nRF91 modems include secure storage for TLS credentials. This may be used to authenticate with Golioth. The assets are stored separately from the firmware, and once written, they cannot be read back from the device. This guide shows the process of storing and using credentials.

Adding sound to the Aludel Elixir based Reference Designs

This post highlights moving code from one Zephyr project to another and all the considerations for code portability.

Want to stay up to date with the latest news?

Subscribe to our newsletter and get updates every 2 weeks. Follow the latest blogs and industry trends.