CDISC_Library_XQuery.xq
(: Copyright 2020 Jozef Aerts.
Licensed under the Apache License, Version 2.0 (the "License");
You may not use this file except in compliance with the License.
You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, 
software distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and limitations under the License.
:)


(: Example XQuery calling the CDISC Library using the API :)
(: apikey is passed from external :)
declare variable $apikey external;

(: The query itself, getting the SEND-CT version 2018-09-28 :)
let $query := 'https://library.cdisc.org/api/mdr/ct/packages/sendct-2018-09-28'

(: The XQuery standard does not natively support basic authentication.
The EXPath extension 'http-client' ( see http://expath.org/modules/http-client/) however does support it.
Some free/open source libraries like BaseX do support this 'http-client' extension.
So you might want to use the BaseX library to run such queries e.g. from Java programs.
:)
let $resp := http:send-request(
  <http:request method='get' href='{$query}'>
   	<http:header name="api-key" value="{$apikey}"/>  
  </http:request>)
return <test>{$resp/json}</test>