Documentation

Flux experimental http requests package

The requests package is experimental and subject to change at any time. By using this package, you accept the risks of experimental functions.

The Flux experimental HTTP requests package provides functions for transferring data using HTTP protocol. Import the experimental/http/requests package:

import "experimental/http/requests"

Options

The experimental/http/requests package includes the following options:

import "experimental/http/requests"

option requests.defaultConfig = {
    insecureSkipVerify: false,
    timeout: 0ns,
}

defaultConfig

Global default for all HTTP requests using the experimental/http/requests package. Changing this option affects all other packages using the experimental/http/requests package. To change configuration options for a single request, pass a new configuration record directly into the corresponding function.

The requests.defaultConfig record contains the following properties:

  • insecureSkipVerify: Skip TLS verification (boolean). Default is false.
  • timeout: HTTP request timeout (duration). Default is 0ns (no timeout).

See examples below.

Functions

Examples

Change HTTP configuration options globally

Modify the requests.defaultConfig option to change all consumers of the experimental/http/requests package.

import "experimental/http/requests"

option requests.defaultConfig = {
    // Set a default timeout of 5s for all requests
    timeout: 0ns,
    insecureSkipVerify: true,
}

Change configuration for a single request

To change the configuration for a single request, extending the default configuration with only the configuration values you need to customize.

import "experimental/http/requests"

// NOTE: Flux syntax does not yet let you specify anything but an identifier as
// the record to extend. As a workaround, this example rebinds the default
// configuration to a new name, "config".
// See https://github.com/influxdata/flux/issues/3655
defaultConfig = requests.defaultConfig
config = {defaultConfig with
     // Change the timeout to 60s for this request
     // NOTE: We don't have to specify any other properites of the config because we're
     // extending the default.
     timeout: 60s,
}
response = requests.get(url:"http://example.com", config: config)

requests.peek(response: response)

Was this page helpful?

Thank you for your feedback!


Upgrade to InfluxDB Cloud or InfluxDB 2.0!

InfluxDB Cloud and InfluxDB OSS 2.0 ready for production.