dcHttpExt 1.1

A simple API client

Overview

The Pod provides the Axon function - dcHttp(). The function provides a simple, lightweight, implementation for REST API calls. The method can be used to retrieve or create new records at an external API address. Users of this extension are welcome to use, edit and add to the extension and related source code as they see fit.

Parameters

  • dcHttp(uri,headers,body,method)
  • uri - enclosed with ` characters.
  • method - Must be a of type string, either GET or POST. Cannot be null.
  • headers - Must be one of; an empty dict, a dict of key-value pairs, or null.
  • body - Must be of type string, or null. If dict is required for body data (Common to have json body data for an api request), the dict must be enclosed all in a string, then use escape characters for the inner quotations (see code example 2). If body data is present, header must contain a content-type header (typically "application/json").
  • reurn type - The response body of the call, as type String. At this stage, other response data is only availabe implicitly.
  • dcHttpResponse(uri,headers,body,method)
  • Use the same as dcHttp().
  • Returns a dict with keys "responseString" and "responseCode".
  • accessing responseString will return what dcHttp method returns.
  • accessing responseCode will return the HTTP calls response status.

Examples

  1. We perform a "GET" request and check the status returned.
    () => do
      uri: `https://exampleblog/posts/5`
      method: "GET"
      headers: null
      body: null
      code: dcHttpResponse(uri,headers,body,method)["responseCode"]
      return code
    end
  2. We perform a "GET" request to our blogs api, no headers or body are provided.
    () => do
      uri: `https://exampleblog/posts/5`
      method: "GET"
      headers: null
      body: null
      return dcHttp(uri,headers,body,method)
    end
  3. We perform a "POST" request to our blogs api, to create a new record. A content type is specified in the header, with body data described as a string enclosed dictionary.
    () => do
      uri: `https://exampleblog.com/new`
      method: "POST"
      headers: {"Content-Type":"application/json"}
      body: "{\"key1\":\"value1\",\"key2\":\"value2\"}"
      return dcHttp(uri,headers,body,method)
    end

Errors

Efforts have been made to mitigate run time exceptions, and to help with compiler exceptions. Please send bug reports to [email protected]