2.1 KiB
2.1 KiB
title | description | menu | weight | ||||||
---|---|---|---|---|---|---|---|---|---|
http.get() function | The `http.get()` function submits an HTTP GET request to the specified URL and returns the HTTP status code, response body, and response headers. |
|
401 |
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
import "experimental/http"
http.get(
url: "http://localhost:9999/",
headers: {x:"a", y:"b", z:"c"},
timeout: 30s
)
Parameters
url
The URL to send the GET request to.
Data type: String
headers
Headers to include with the GET request.
Data type: Object
timeout
Timeout for the GET request.
Default is 30s
.
Data type: Duration
Response format
http.get
returns an object 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: Object
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:9999/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,
}))