HTTP - script API
Functions to execute HTTP requests.
This page describes StackState version 4.3.
Sometimes it may be useful to process the retrieved topology or telemetry data using an external tool. For example, to perform analysis using a custom Python script, a cloud service or an Machine Learning framework. StackState can call out to any external service via HTTP using the functions in this script API.
The permission execute-restricted-scripts is required to execute scripts using the HTTP script API in the StackState UI analytics environment. For details, see the analytics page permissions.

Function: get

Submit HTTP get request.
Args:
  • uri - uri of the HTTP server.
Builder methods:
  • .timeout(time: Duration) - make the request timeout after time has elapsed.
  • .param(name: String, value: String) - specify the query.
  • .header(name: String, value: String) - specify the header.
Return type:
  • Async: HttpScriptApiTextResponse or HttpScriptApiJsonResponse if .jsonResponse() is used.
Example:
1
Http.get("https://www.google.com/?q=apples")
2
.timeout("30s")
3
.param("name", "value")
4
.header("name", "value")
Copied!

Function: put

Submit HTTP put request.
Args:
  • uri - uri of the HTTP server.
Builder methods:
  • .timeout(time: Duration) - make the request timeout after time has elapsed.
  • .param(name: String, value: String) - specify the query.
  • .header(name: String, value: String) - specify the header.
  • .contentType(contentType: String) - specify the content type, for example "application/text".
  • .textRequest(text: String) - specify the text of the request.
  • .jsonRequest(json: Goovy.lang.Closures) - specify the JSON of the request. This will wrap the given closure with a JsonBuilder.
  • .jsonBody() - get the body of the JSON response.
  • .jsonResponse() - get the JSON response.
Return type:
  • AsyncScriptResult[HttpScriptApiTextResponse] or AsyncScriptResult[HttpScriptApiJsonResponse] if .jsonResponse() is used.
Example:
1
Http.put("http://http_server:8080/api")
2
.timeout("30s")
3
.param("name", "value")
4
.header("name", "value")
5
.contentType("application/text")
6
.textRequest("{'property', 'value'}")
7
.jsonResponse()
Copied!

Function: post

Submit HTTP post request.
Args:
  • uri - uri of the HTTP server.
Builder methods:
  • .timeout(time: Duration) - make the request timeout after time has elapsed.
  • .param(name: String, value: String) - specify the query.
  • .header(name: String, value: String) - specify the header.
  • .contentType(contentType: String) - specify the content type, for example "application/text".
  • .textRequest(text: String) - specify the text of the request.
  • .jsonRequest(json: Goovy.lang.Closures) - specify the JSON of the request. This will wrap the given closure with a JsonBuilder.
  • .jsonBody() - get the body of the JSON response.
  • .jsonResponse() - get the JSON response.
Return type:
  • AsyncScriptResult[HttpScriptApiTextResponse] or AsyncScriptResult[HttpScriptApiJsonResponse] if .jsonResponse() is used.
Example:
1
Http.post("http://http_server:8080/api")
2
.timeout("30s")
3
.param("name", "value")
4
.header("name", "value")
5
.jsonRequest {
6
basicProperty "value"
7
objectProperty {
8
basicProperty 42.0
9
}
10
listProperty (["list item"])
11
}.jsonBody()
Copied!

Function: delete

Submit HTTP delete request.
Args:
  • uri - uri of the HTTP server.
Builder methods:
  • .timeout(time: Duration) - make the request timeout after time has elapsed.
  • .param(name: String, value: String) - specify the query.
  • .header(name: String, value: String) - specify the header.
Return type:
  • AsyncScriptResult[HttpScriptApiTextResponse] or AsyncScriptResult[HttpScriptApiJsonResponse] if .jsonResponse() is used.
Example:
1
Http.delete("http://http_server:8080/api")
2
.timeout("30s")
3
.param("name", "value")
4
.header("name", "value")
Copied!

Function: options

Submit HTTP options request.
1
Http.options("http://http_server:8080/api")
2
.timeout("30s")
3
.param("name", "value")
4
.header("name", "value")
Copied!

Function: patch

Submit HTTP patch request.
Args:
  • uri - uri of the HTTP server.
Builder methods:
  • .timeout(time: Duration) - make the request timeout after time has elapsed.
  • .param(name: String, value: String) - specify the query.
  • .header(name: String, value: String) - specify the header.
  • .contentType(contentType: String) - specify the content type, for example "application/text".
  • .textRequest(text: String) - specify the text of the request.
  • .jsonRequest(json: Goovy.lang.Closures) - specify the JSON of the request. This will wrap the given closure with a JsonBuilder.
  • .jsonBody() - get the body of the JSON response.
  • .jsonResponse() - get the JSON response.
Return type:
  • AsyncScriptResult[HttpScriptApiTextResponse] or AsyncScriptResult[HttpScriptApiJsonResponse] if .jsonResponse() is used.
Example:
1
Http.patch("http://http_server:8080/api")
2
.timeout("30s")
3
.param("name", "value")
4
.header("name", "value")
5
.textRequest("{'property', 'value'}")
Copied!

Function: head

Submit HTTP head request.
Args:
  • uri - uri of the HTTP server.
Builder methods:
  • .timeout(time: Duration) - make the request timeout after time has elapsed.
  • .param(name: String, value: String) - specify the query.
  • .header(name: String, value: String) - specify the header.
Return type:
  • AsyncScriptResult[HttpScriptApiTextResponse] or AsyncScriptResult[HttpScriptApiJsonResponse] if .jsonResponse() is used.
Example:
1
Http.head("http://http_server:8080/api")
2
.timeout("30s")
3
.param("name", "value")
4
.header("name", "value")
Copied!
Last modified 4mo ago