Skip to content

Web Services functions

Oswaldo Baptista Vicente Junior edited this page Oct 21, 2022 · 1 revision

HTTP Get

Returns data from a Web Service or RESTful API, as string.

httpGet("http://sampleservice.com/jep/v1/wheather")

Note: This is similar to invoking httpResponse(http("GET", "http://sampleservice.com/data/v1/wheather"))

HTTP Get with custom headers

Returns data from a Web Service or RESTful API, as string, with custom HTTP headers in the request.

httpGet("http://sampleservice.com/jep/v1/wheather", httpHeader("Accept=text/xml"))

Note: Refer to the httpHeaders function for additional details.

Invoke HTTP method

Invokes the requested method towards a Web Service or RESTful API, with a given request body, and returns a WebServiceResponse.

http("POST", "http://sampleservice.com/jep/v1/customer", requestBody)

Note: A WebServiceResponse is an object that contains the HTTP status code and the response body/payload. These values can be retrieved by the functions httpStatusCode() and httpResponse(), respectively.

Invoke HTTP method with custom headers

Invokes the requested method towards a Web Service or RESTful API, with a given request body and a custom HTTP headers, and returns a WebServiceResponse.

http("POST", "http://sampleservice.com/jep/v1/customer", requestBody, httpHeader("Media-Type=text/xml"))

Note: Refer to the httpHeaders function for additional details.

HTTP header(s)

This function groups together a variable number of string arguments containing HTTP header entries for usage with the http() and httpGet() functions. Each entry is a string containing a key, a separator, and a value. A separator can be either an equal sign (=) or a colon (:). For example, an entry can be defined as "Accept=text/xml" or "Accept:text/xml".

httpHeader("Accept=text/xml")
httpHeaders("Accept=text/xml", "Authentication=Basic dXNlcjpwYXNz")

Basic authorization header

Generates a basic authorization header from a given username and password.

basicAuthorizationHeader("Aladdin", "OpenSesame") //result: "Basic QWxhZGRpbjpPcGVuU2VzYW1l"

HTTP status code getter

Returns the HTTP status code, given a WebServiceResponse object, returned by the http() function.

httpStatusCode(webServiceResponse)

HTTP response body getter

Returns the HTTP response body as string, given a WebServiceResponse object, returned by the http() function.

httpResponse(webServiceResponse)