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.

*Function type: Miscellaneous*

  1. import "experimental/http"
  2. http.get(
  3. url: "http://localhost:8086/",
  4. headers: {x:"a", y:"b", z:"c"},
  5. timeout: 30s
  6. )

Parameters

url

The URL to send the GET request to.

*Data type: String*

headers

Headers to include with the GET request.

*Data type: Record*

timeout

Timeout for the GET request. Default is 30s.

*Data type: Duration*

Response format

http.get returns a record that contains the following:

statusCode

The HTTP status code returned by the GET request.

*Data type: Integer*

body

The response body.

*Data type: Byte Array*

headers

Headers included with the response.

*Data type: Record*

Examples

Get the status of InfluxDB OSS
  1. import "influxdata/influxdb/secrets"
  2. import "experimental/http"
  3. import "csv"
  4. token = secrets.get(key: "READONLY_TOKEN")
  5. response = http.get(
  6. url: "http://localhost:8086/health",
  7. headers: {Authorization: "Token ${token}"}
  8. )
  9. httpStatus = response.statusCode
  10. responseBody = string(v: response.body)
  11. responseHeaders = response.headers
  12. // Response header data
  13. date = responseHeaders.Date
  14. contentLenth = responseHeaders["Content-Length"]
  15. contentType = responseHeaders["Content-Type"]
  16. // Use the returned data in a stream of tables
  17. csvData = "#datatype,string,long,string
  18. #group,false,false,false
  19. #default,,,
  20. ,result,table,column
  21. ,,0,*
  22. "
  23. csv.from(csv: csvData)
  24. |> map(fn: (r) => ({
  25. httpStatus: httpStatus,
  26. responseBody: responseBody,
  27. date: date,
  28. contentLenth: contentLenth,
  29. contentType: contentType,
  30. }))