· 6 years ago · Sep 22, 2019, 04:04 PM
1xquery version "3.1";
2
3declare namespace http = "http://expath.org/ns/http-client";
4
5import module namespace jsjson="http://johnsnelson/json" at "/db/apps/usermanager/modules/jsjson.xqm";
6declare option exist:serialize "method=html5 media-type=text/html";
7
8let $request := <http:request method = "GET"
9 href="https://api.weather.yandex.ru/v1/forecast?lat=55.7522200&lon=37.6155600&lang=ru_RU&limit=2&hours=true&extra=false">
10 <http:header name="X-Yandex-API-Key" value = "PLACE YOUR KEY HERE"/>
11</http:request>
12let $req :=hc:send-request($request)
13let $rbody := $req[2]
14let $json-txt := util:base64-decode($rbody)
15let $json := parse-json($json-txt)
16
17return <html>
18 <head>
19 <title>
20 Yandex.Weather API XQuery Sample at eXist-db engine
21 </title>
22 </head>
23 <body>
24 <textarea>{jsjson:parse-json($json-txt)}</textarea>
25 </body>
26</html>