requests.post() function
The requests.post()
function is experimental and subject to change at any time.
By using this function, you accept the risks of experimental functions.
requests.post()
makes an HTTP request using the POST request method.
import "experimental/http/requests"
requests.post(
url: "http://example.com",
params: ["example-param": ["example-param-value"]],
headers: ["Example-Header": "example-header-value"],
body: bytes(v: ""),
config: requests.defaultConfig,
)
requests.post()
returns a record with the following properties:
- statusCode: HTTP status code of the request.
- body: Response body. A maximum size of 100MB is read from the response body.
- headers: Response headers.
Parameters
url
URL to send the request to.
The URL should not include any query parameters.
Use params
to specify query parameters.
params
Set of key-value pairs to add to the URL as query parameters. Query parameters are URL-encoded. All values for a key are appended to the query.
headers
Set of key values pairs to include as request headers.
body
Data to send with the request.
config
Set of request configuration options. See HTTP configuration option examples.
Examples
- Make a POST request
- Make a POST request with authorization
- Make a POST request with a JSON body
- Output HTTP POST response data in a table
Make a POST request
import "json"
import "experimental/http/requests"
requests.post(url:"http://example.com", body: json.encode(v: {data: {x:1, y: 2, z:3}))
Make a POST request with authorization
import "json"
import "experimental/http/requests"
import "influxdata/influxdb/secrets"
token = secrets.get(key: "TOKEN")
requests.post(
url: "http://example.com",
body: json.encode(v: {data: {x: 1, y: 2, z: 3}}),
headers: ["Authorization": "Bearer ${token}"],
)
Make a POST request with a JSON body
Use json.encode()
to encode a Flux record as
a JSON object.
import "experimental/http/requests"
import "json"
requests.post(
url: "https://goolnk.com/api/v1/shorten",
body: json.encode(v: {url: "http://www.influxdata.com"}),
headers: ["Content-Type": "application/json"],
)
Output HTTP POST response data in a table
To quickly inspect HTTP response data, use requests.peek()
to output HTTP response data in a table.
import "experimental/http/requests"
response = requests.post(url: "http://example.com")
requests.peek(response: response)
Was this page helpful?
Thank you for your feedback!
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, use the following resources:
InfluxDB Cloud customers can contact InfluxData Support.