http.get() function
The http.get()
function is experimental and subject to change at any time.
By using this function, you accept the risks of experimental functions.
The http.get()
function submits an HTTP GET request to the specified URL and
returns the HTTP status code, response body, and response headers.
import "experimental/http"
http.get(
url: "http://localhost:8086/",
headers: {x:"a", y:"b", z:"c"},
timeout: 30s
)
Parameters
url
The URL to send the GET request to.
headers
Headers to include with the GET request.
timeout
Timeout for the GET request.
Default is 30s
.
Response format
http.get
returns a record that contains the following:
statusCode
The HTTP status code returned by the GET request.
body
The response body.
headers
Headers included with the response.
Examples
Get the status of InfluxDB OSS
import "influxdata/influxdb/secrets"
import "experimental/http"
import "csv"
token = secrets.get(key: "READONLY_TOKEN")
response = http.get(url: "http://localhost:8086/health", headers: {Authorization: "Token ${token}"})
httpStatus = response.statusCode
responseBody = string(v: response.body)
responseHeaders = response.headers
// Response header data
date = responseHeaders.Date
contentLenth = responseHeaders["Content-Length"]
contentType = responseHeaders["Content-Type"]
// Use the returned data in a stream of tables
csvData = "#datatype,string,long,string
#group,false,false,false
#default,,,
,result,table,column
,,0,*
"
csv.from(csv: csvData)
|> map(
fn: (r) => ({
httpStatus: httpStatus,
responseBody: responseBody,
date: date,
contentLenth: contentLenth,
contentType: contentType,
}),
)
Support and feedback
Thank you for being part of our community! We welcome and encourage your feedback and bug reports for Flux and this documentation. To find support, the following resources are available:
InfluxDB Cloud customers can contact InfluxData Support.