dcHttpExt

A simple API client
dcHttpExt
v1.1

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]

Published by Direct Control
Pricing options
dcHttpExt
A simple API client
FREE
Download now
Also available via SkyArc Install Manager
Package details
Version1.1
LicenseMIT
Build date6 months ago
on 23rd Apr 2018 00:22:25 UTC
Depends on
File namedcHttpExt.pod
File size7.94 kB
MD53992476a2d981879d459874e13039922
SHA1 b740843837310fdb08c3b89198874988b3f5f30e
Published by
Direct ControlDownload now
Also available via SkyArc Install Manager
Tags
Fantom Pod