Astarte.Flow.Blocks.HttpSource (astarte_flow v0.1.0)

This is a producer block that generates messages by polling HTTP URLs with a GET request.

It works by specifying a base_url and a list of target_paths to perform requests on. HttpSource will perform GET requests in a round robin fashion on all target_paths, waiting polling_interval_ms between two consecutive requests.

If the request can't be performed or an error status (>= 400) is returned, no message is produced.

If the request succeeds, HttpSource produces an %Astarte.Flow.Message{} containing these fields:

  • key contains the target_path of the request.
  • data contains the body of the response.
  • type is always :binary.
  • subtype is populated with the contents of the content-type HTTP header, defaulting to "application/octet-stream" if it's not found.
  • metadata contains the "Astarte.Flow.Blocks.HttpSource.base_url" key with base_url as value. Moreover, it contains all the HTTP headers contained in the response with their keys prefixed with "Astarte.Flow.HttpSource.".
  • timestamp contains the timestamp (in microseconds) the response was received.

Link to this section Summary

Functions

Starts the HttpSource.

Link to this section Functions

Link to this function

start_link(opts)

@spec start_link(options) :: GenServer.on_start()
when options: [option],
     option:
       {:base_url, url :: String.t()}
       | {:target_paths, target_paths :: [String.t(), ...]}
       | {:polling_interval_ms, polling_interval_ms :: number()}
       | {:headers, headers},
     headers: [{String.t(), String.t()}] | %{optional(String.t()) => String.t()}

Starts the HttpSource.

options

Options

  • :base_url (required) - The base URL for the GET requests. This gets prepended to the target_path when performing a request.
  • :target_paths (required) - A non-empty list of target paths for GET requests.
  • :polling_interval_ms - The interval between two consecutive GET requests, in milliseconds. Defaults to 1000 ms.
  • :headers - A list of {key, value} tuples where key and value are String and represent headers to be set in the GET request. Headers can also be passed as a String => String map.
  • :ignore_ssl_errors - If true, ignore SSL errors that happen while performing the request. Defaults to false.