HTTP API

FLX app provide a HTTP API that provides the common HTTP methods as functions. The implementation is based on Fuel library.

HTTP API Functions

Cancels the given request.

  • request – a CancellableRequest

Returns: true if the request was actually cancelled, otherwise false.

Executes a HTTP DELETE request with the given url. A callback function with signature (result:HttpResult) is required since the request is asynchronous.

  • url – a String specifying a valid URL
  • callback – a FunctionObject, e.g. an anonymous function (see Functions with single parameter of type HttpResult.

Returns: a CancellableRequest

Executes a HTTP DELETE request with the given url. A callback function with signature (result:HttpResult) is required since the request is asynchronous. Parameters are given as a Map which defines one or more key -> value pairs.

  • url – a String specifying a valid URL
  • callback – a FunctionObject, e.g. an anonymous function (see Functions with single parameter of type HttpResult.
  • parameters – a Map containing key-value pairs

Returns: a CancellableRequest

Executes a HTTP GET request with the given url. A callback function with signature (result:HttpResult) is required since the request is asynchronous.

  • url – a String specifying a valid URL
  • callback – a FunctionObject, e.g. an anonymous function (see Functions with single parameter of type HttpResult.

Returns: a CancellableRequest

Executes a HTTP GET request with the given url. A callback function with signature (result:HttpResult) is required since the request is asynchronous. Parameters are given as a Map which defines one or more key -> value pairs.

  • url – a String specifying a valid URL
  • callback – a FunctionObject, e.g. an anonymous function (see Functions with single parameter of type HttpResult.
  • parameters – a Map containing key-value pairs

Returns: a CancellableRequest

Executes a HTTP POST request with the given url. A callback function with signature (result:HttpResult) is required since the request is asynchronous.

  • url – a String specifying a valid URL
  • callback – a FunctionObject, e.g. an anonymous function (see Functions with single parameter of type HttpResult.

Returns: a CancellableRequest

Executes a HTTP POST request with the given url. A callback function with signature (result:HttpResult) is required since the request is asynchronous. Parameters are given as a Map which defines one or more key -> value pairs.

  • url – a String specifying a valid URL
  • callback – a FunctionObject, e.g. an anonymous function (see Functions with single parameter of type HttpResult.
  • parameters – a Map containing key-value pairs

Returns: a CancellableRequest

Executes a HTTP PUT request with the given url. A callback function with signature (result:HttpResult) is required since the request is asynchronous.

  • url – a String specifying a valid URL
  • callback – a FunctionObject, e.g. an anonymous function (see Functions with single parameter of type HttpResult.

Returns: a CancellableRequest

Executes a HTTP PUT request with the given url. A callback function with signature (result:HttpResult) is required since the request is asynchronous. Parameters are given as a Map which defines one or more key -> value pairs.

  • url – a String specifying a valid URL
  • callback – a FunctionObject, e.g. an anonymous function (see Functions with single parameter of type HttpResult.
  • parameters – a Map containing key-value pairs

Returns: a CancellableRequest

Returns the value of the given httpResult as a String.

  • *httpResult* – a HttpResult

Returns: a String

Gets the JSON value from the given httpResult object. See the JSON API page.

  • httpResult – a HttpResultobject

Returns: a JsonObject

Example

Below is a simple example of making a GET request to obtain a joke from Chuck Norris Jokes API.

  1. The Jokes API path.
  2. Creating the URL. Function str concatenates all its arg values to a String. (One could of course just define that url is “https://api.chucknorris…”)
  3. Invoke the GET function with the url and a callback.
  4. A Callback object has a handler code defined in a code block.
  5. A Callback can have also optional arguments. In this case there is single parameter for passing the HttpResult object, which is received asynchronously as a GET function response, to the Callback object. The code block implementing the calback handler is shown below.
  1. The response parameter of Callback object. In this example the value of the parameter is of type HttpResult.
  2. The JSON value payload is obtained from the received HttpResult object.
  3. The actual joke property value is obtained from the response JSON using property key "value".
  4. The joke value is converted to a String and printed.