Acme-CPANModulesBundle-Import-MojoliciousAdvent-2017
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
devdata/https_mojolicious.io_blog_2017_12_08_day-8-mocking-a-rest-api view on Meta::CPAN
<pre><code>$ perl test-api.pl get /servers
[
{ "ip": "10.0.0.1", "os": "Debian 9" },
{ "ip": "10.0.0.2", "os": "Debian 8" }
]
</code></pre>
<p>So now I can write a bunch of JSON in my script and it will be exposed
as an API. But I'd like it to be easier to make lists of things: REST
APIs often have one endpoint as a list and another as an individual item
in that list. We can make a list by composing our individual parts using
Mojolicious templates and the <code>include</code> template helper:</p>
<pre><code class="hljs"><span class="hljs-comment"># test-api.pl</span><span class="hljs-comment">
</span><span class="hljs-keyword">use</span> <span class="hljs-function">Mojolicious::Lite</span>;
any '<span class="hljs-string">/*path</span>' => <span class="hljs-keyword">sub </span>{
<span class="hljs-keyword">my</span> ( <span class="hljs-type">$c</span> ) = <span class="hljs-type">@_</span>;
<span class="hljs-keyword">return</span> <span class="hljs-type">$c</span>-><span class="hljs-type">render</span>(
template => <span class="hljs-type">$c</span>-><span class="hljs-type">stash</span>( '<span class="hljs-string">path</span>' ),
<span class="hljs-function">format</span> => '<span class="hljs-string">json</span>',
view all matches for this distributionview release on metacpan - search on metacpan
( run in 1.585 second using v1.00-cache-2.02-grep-82fe00e-cpan-4673cadbf75 )