Table of Contents

REST API client

Module RSTMOD REST API client

Description

HTTP Library that makes HTTP requests simpler and more human-friendly.

Provides functionality for convenient REST API communication including the following features:
* Utilizing HTTP methods: GET, POST, PUT, DELETE
* Saving endpoint configuration in static data (via DBISYS)
* Establishing connection without static settings (via InitializeWithURL)
* Managing security settings per endpoint (see documentation for AUTMOD)
* Logging (if activated) all verbose information (request, response, debug data)

How to use it:

1. To have endpoint settings stored - add instance of RSTMOD to DBISYS\SYSGRP with object name related to endpoint.
E.g: RSTMOD : RSTXLS

2. Add description of the endpoint via SYSTBL to codetable RSTSRV. E.g:
RSTXLS - Excel Handler

3. Neccessary panels for configuration will appear automaticaly in DBISYS. Configure endpoint and save settings

4. Add the same instance (i.e. RSTMOD : RSTXLS) to the place where the API communication should take place

5. To have HTTP-communication with configured endpoint - the following commands to be executed:

- Load settings (mandatory to call before any other command)

RSTXLS.Initialize  


- Add nodes to URL:

RSTXLS.AddToUrl( <url node> )


- Add parameters to URL:

RSTXLS.AddParToUrl( <name>, <value> )


- Add parameters to Header of the request

RSTXLS.AddParToHeader( <name>, <value> ) 


- Set request body with given content

RSTXLS.SetRequest( <request_body> )


- Perform given HTTP request using the previously set parameters:

RSTXLS.RestPost\\
if ErrorCode > 0 then\\
# necessary error handling. Standard HTTP errors are reraised with +1000. I.e. HTTP error 404 will be raised as 1404.\\
endif\\


- Retrieve response from HTTP call

$response = RSTXLS.GetResponse


If the format is JSON, then the following call is valid to start working with JSON:

$handle = TDJsonInit( RSTXLS.GetResponse )



Properties

Property YES/NO
Single page frame No
Show toolbar No
Show menu No
Show statusbar No
Show hint No
Fit panel size No

Datafields

Name Description Data Type Len Dec. View lines View type Inst. Visible Codetable
PANSTA Panel Status 'E'dit 'I'nfo Text 1 1 Edit Yes Public
NAME Name Text 100 1 Edit Yes Public
STMIN Input Stream 1 0 Source Yes Private
STMOUT Output Stream 1 0 Source Yes Private
STMDBG Debug Stream 1 0 Source Yes Public
FMT Format Text 4 1 Edit Yes Public Embedded
SRVNAM Rest Instance Name Text 10 1 Edit Yes Private
URL Endpoint URL Block 64 32 4 Block Yes Private
PARURL Parameters for URL Block 64 32 Block Yes Private
CURURL Current URL for calling Block 64 32 Block Yes Private
SRVPNT Parent Module of REST Instance Text 10 1 Edit Yes Private
LBLVBS Label for Verbose Folder Text 100 1 Edit Yes Private
HEADER Header for request Stream 1 1 Source Yes Private
DBGSAV Save Debug Info Text 1 1 Edit Yes Public
REQSAV Save Request Text 1 1 Edit Yes Public
RESSAV Save Response Text 1 1 Edit Yes Public
APINAM API Name Text 30 1 Edit Yes Public
HDROUT Header for response Stream 1 1 Source Yes Private
TSTFLG Test Mode Text 1 1 Edit Yes Public
TSTHTPSTA Test Http Response Status Code Text 3 1 Edit Yes Public HTPSTA
TSTHTPBODY Test Http Response Body Stream 1 0 Source Yes Public
TSTHTPHDR Test Http Response Header Stream 1 0 Source Yes Public
HTPSTA Http Response Status Code Numeric 3 0 Edit Yes Public
HTPSTATXT Http Response Status Text Text 80 1 Edit Yes Public
APITYP API Type Text 8 1 Edit Yes Public Embedded
OLDAPITYP Old API Type Text 8 1 Edit Yes Private
CNTLEN Http Header: Content Length Text 1 1 Edit Yes Private

Datafield Description and Properties

Datafield STMIN Input

Description

Contains content of request.

To set request - use method SetRequest


Datafield STMOUT Output

Description

Contains content of response.

To get response - use method GetResponse


Datafield FMT Format

Codetable
Code Text
XML text/xml
JSON application/json
TXT text/plain
SOAP application/soap+xml

Datafield URL Endpoint URL

Description

URL for REST base endpoint

Maximum size 2048

To add nodes to URL - use AddToURL To add parameters to URL - use AddParToURL To get full URL - use GetURI


Datafield PARURL Parameters for URL

Description

Includes parameters of URL

To add parameter - use function AddParToUrl


Datafield CURURL Current URL for calling

Description

Contains current URL.

To get current URL - use GetURI


Datafield SRVPNT Parent Module of REST Instance

Description

Indicates parent module of current instance of RSTMOD. Used as security sontext


Datafield HEADER Header for request

Description

Contains header for the request.

To set header - see method AddParToHeader


Datafield DBGSAV Save Debug Info

Description

When set to non-empty - debug info after API call can be found in stream DBGSTM and saved in debug folder

For the folder - see function SYSTDC.GetVerboseFolder


Datafield REQSAV Save Request

Description

When set to non-empty - request of API call is saved to debug folder.

For the folder - see function SYSTDC.GetVerboseFolder


Datafield RESSAV Save Response

Description

When set to non-empty - response of API call is saved to debug folder.

For the folder - see function SYSTDC.GetVerboseFolder


Datafield HDROUT Header for response

Description

PCH-717 Contains header for the response.

To get header parameter - see method GetHttpHeaderParameter


Datafield TSTHTPBODY Test Http Response Body

Description

Contains content of http response body


Datafield TSTHTPHDR Test Http Response Header

Description

PCH-717 Contains content of http response header


Datafield APITYP API Type

Codetable
Code Text
REST REST API
SOAP11 SOAP API v1.1
SOAP12 SOAP API v1.2

Panels

Panel Type Description
CONFIG FramePanel REST API Configuration
RESTCFG FramePanel REST API configuration
TESTCFG FramePanel Test configuration

FramePanel CONFIG

Properties
Property Value
Width 788
Height 528
Popup position-X 0
Popup position-Y 0
Visible No
Read only No
Show toolbar No
Instanciated Yes
Popup panel No
Global No

FramePanel RESTCFG

Properties
Property Value
Width 788
Height 298
Popup position-X 0
Popup position-Y 0
Visible No
Read only No
Show toolbar No
Instanciated No
Popup panel No
Global No

FramePanel TESTCFG

Properties
Property Value
Width 788
Height 528
Popup position-X 0
Popup position-Y 0
Visible No
Read only No
Show toolbar No
Instanciated Yes
Popup panel No
Global No

Rules

Rule Name Additional
function GetHttpHeaderParameter text method
function GetResponse text method
function GetResponsePayload text method
function GetURI text method
sub AddParToHeader method
sub AddParToUrl method
sub AddToURL method
sub Initialize method
sub InitializeWithURL method
sub LoadSettings method
sub LoadSettingsCus method
sub Reset method
sub RestDelete method
sub RestGet method
sub RestPost method
sub RestPut method
sub SaveSettings method
sub SaveSettingsCus method
sub SetRequest method

Rules Description and Comments

function GetResponse : text method

This method returns content of response from the previous HTTP call


function GetURI : text method

Returns complete URI of the endpoint including all parameters and added nodes


sub AddParToHeader( in ArgPar text, in ArgValue text ) method

Adds pair “ArgPar”: “ArgValue” to the header of REST call

ArgPar - name of parameter
ArgValue - value of the parameter


sub AddParToUrl( in ArgPar text, in ArgVal text ) method

Adds parameter + value to URL for REST API calling

Corresponding functions: RestGet, RestPost, RestPut, RestDelete, AddToURL


sub AddToURL( in ArgNode text ) method

Adds node to URL

Corresponding functions: RestGet, RestPost, RestPut, RestDelete, AddParToURL


sub Initialize method

Initialize instance of RSTMOD with statically defined settings

Settings are stored in AppIniFile under section named as instance of RSTMOD


sub InitializeWithURL( in ArgURL text ) method

Initialize RSTMOD with given URL


sub RestDelete method

Calls for REST DELETE method
Errorcode must be checked afterwards
Result can be retrieved by method GetResponse

Corresponding functions: RestGet, RestPost, AddToURL, AddParToURL


sub RestGet method

Calls for REST GET method
Errorcode must be checked afterwards
Result can be retrieved by method GetResponse

Corresponding functions: RestPost, RestDelete AddToURL, AddParToURL


sub RestPost method

Calls for REST POST method
Errorcode must be checked afterwards
Result can be retrieved by method GetResponse

Corresponding functions: RestGet, AddToURL, AddParToURL


sub RestPut method

Calls for REST PUT method
Errorcode must be checked afterwards
Result can be retrieved by method GetResponse

Corresponding functions: RestGet, RestPost, AddToURL, AddParToURL


sub SetRequest( in ArgReq text ) method

This method is used to set request for the upcoming HTTP call

ArgReq - content of request to be sent


sub Reset method

Resets fields of RSTMOD to the state of initialization (without clearing the settings)
Might be useful in settings transactions to use settings not from ini-file but from current “online” settings


function GetHttpHeaderParameter( in ArgPar text ) : text method

returns the value of the response http header parameter ArgPar

ArgPar: name of http header parameter

returns: value of http header parameter


function GetResponsePayload : text method

This method returns the content of the functional body (payload data) of the response from the previous HTTP call
It strips away from the response all technical headers (control data)


Modules

Module class Instance Comment
ENCMOD ENCMOD
AUTMOD AUTMOD
SOAAPI SOAAPI
SYSTDC SYSTDC
SYSTDT SYSTDT
SSNAPI SSNAPI