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:
keycontains thetarget_pathof the request.datacontains the body of the response.typeis always:binary.subtypeis populated with the contents of thecontent-typeHTTP header, defaulting to"application/octet-stream"if it's not found.metadatacontains the"Astarte.Flow.Blocks.HttpSource.base_url"key withbase_urlas value. Moreover, it contains all the HTTP headers contained in the response with their keys prefixed with"Astarte.Flow.HttpSource.".timestampcontains 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 thetarget_pathwhen 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 wherekeyandvalueareStringand represent headers to be set in the GET request. Headers can also be passed as aString => Stringmap.:ignore_ssl_errors- Iftrue, ignore SSL errors that happen while performing the request. Defaults tofalse.