RESTful resources¶
RESTful resource are defined by using & as a prefix. The resources can be used to load data into data sections.
In the following example the resource named ‘db’ is configured with a wikipedia api hostname. The ZML implementation loads the JSON data from the path /w/api.php?action=query&list=search&format=json&srsearch=rest. The JSON will be converted and is accessible by using the ‘pages’ context variable.
%import components
%inherit base
@db: 'en.wikipedia.org/w/api.php?action=query&list=search&format=json&srsearch=rest'
#pages: @db
*content:
%for p in pages.query.search:
p: '{p.title}'
The rendered result:
<html>
<head>
<title>zml</title>
</head>
<body>
<p>Rest
</p>
<p>Representational state transfer
</p>
<p>ReStructuredText
</p>
<p>Rest (music)
</p>
<p>Rest in peace
</p>
<p>The Rest
</p>
<p>Bed rest
</p>
<p>Ain't No Rest for the Wicked
</p>
<p>Rabbit at Rest
</p>
<p>The Rest of the Story
</p>
</body>
</html>