Skip to main content

HTTPCALL

result := HTTPCALL( url, httpmethod, responsemimetype, outstructure [, options ] );

resultThe definition name for the resulting recordset.
urlA string containing the URL that hosts the service to invoke. This may contain parameters to the service.
httpmethodA string containing the HTTP Method to invoke. Valid methods are: "GET"
responsemimetypeA string containing the Response MIME type to use. Valid types are: "text/xml"
outstructureA RECORD structure containing the output field definitions. For an XML-based responsemimetype these should use XPATH to specify the exact data path.
optionsA comma-delimited list of optional specifications from the list below.

HTTPCALL is a function that calls a REST service.

Valid options are:

RETRY(count)Specifies re-attempting the call count number of times if non-fatal errors occur. If omitted, the default is three (3).
TIMEOUT(period)Specifies the amount of time to attempt the read before failing. The period is a real number where the integer portion specifies seconds. Setting to zero (0) indicates waiting forever. If omitted, the default is three hundred (300).
TIMELIMIT(period)Specifies the total amount of time allowed for the HTTPCALL. The period is a real number where the integer portion specifies seconds. If omitted, the default is zero (0) indicating no limit.
XPATH(xpath)Specifies the path used to access rows in the output. If omitted, the default is: 'serviceResponse/Results/Result/Dataset/Row'.
ONFAIL(transform)Specifies either the transform function to call if the service fails for a particular record, or the keyword SKIP. The TRANSFORM function must produce a resultype the same as the outstructure and may use FAILCODE and/or FAILMESSAGE to provide details of the failure.
TRIMSpecifies all trailing spaces are removed from strings before output.
HTTPHEADERSpecifies header information to be passed to the service. HTTPCALL supports multiple instances of the HTTPHEADER option if you need to specify multiple key/value header strings.

Example:

worldBankSource := RECORD
  STRING name {XPATH('name')}
END;

OutRec1 := RECORD
  DATASET(worldBankSource) Fred{XPATH('/source')};
END;

raw := HTTPCALL('http://api.worldbank.org/sources', 'GET', 'text/xml', OutRec1, );

OUTPUT(raw);

////Using HTTPHEADER to pass Authorization info
raw2 := HTTPCALL('http://api.worldbank.org/sources', 'GET', 'text/xml', 
                 OutRec1, HTTPHEADER('Authorization','Basic dXNlcm5hbWU6cGFzc3dvcmQ='),
                          HTTPHEADER('MyLiteral','FOO'));

OUTPUT(raw2);