Skip to content

Commit

Permalink
deploy: 215c71c
Browse files Browse the repository at this point in the history
  • Loading branch information
noelwelsh committed Jan 21, 2024
1 parent 62783af commit 3daff97
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion routes/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ <h2 id="constructing-a-route" class="section">Constructing A Route</h2>
<h3 id="type-transformations-for-handlers" class="section">Type Transformations for Handlers</h3>
<p>If you dig into the types produced by <code>Requests</code>, you notice a lot of tuple types are used. Here&#39;s an example, showing a <code>Request</code> producing a <code>Tuple2</code>.</p>
<pre><code class="nohighlight"><span class="keyword">val</span><span> </span><span class="identifier">request</span><span> = </span><span class="type-name">Request</span><span>.</span><span class="identifier">get</span><span>(</span><span class="type-name">Path</span><span>.</span><span class="identifier">root</span><span> / </span><span class="type-name">Param</span><span>.</span><span class="identifier">int</span><span> / </span><span class="type-name">Param</span><span>.</span><span class="identifier">string</span><span>)
</span><span class="comment">// request: Request[*:[Int, *:[String, EmptyTuple]], Unit, Unit, Unit] = krop.route.Request@11ab9062</span></code></pre>
</span><span class="comment">// request: Request[*:[Int, *:[String, EmptyTuple]], Unit, Unit, Unit] = krop.route.Request@3e606b49</span></code></pre>
<p>However, when you come to use a handler with such a request, you can use a normal function with two arguments <em>not</em> a function that accepts a single <code>Tuple2</code>.</p>
<pre><code class="nohighlight"><span class="type-name">Route</span><span>(</span><span class="identifier">request</span><span>, </span><span class="type-name">Response</span><span>.</span><span class="identifier">ok</span><span>(</span><span class="type-name">Entity</span><span>.</span><span class="identifier">text</span><span>))
.</span><span class="identifier">handle</span><span>((</span><span class="identifier">int</span><span>, </span><span class="identifier">string</span><span>) =&gt; </span><span class="string-literal">s&quot;</span><span class="substitution">${int.toString}</span><span class="string-literal">: </span><span class="substitution">${string}</span><span class="string-literal">&quot;</span><span>)</span></code></pre>
Expand Down
3 changes: 2 additions & 1 deletion routes/response.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@
<div id="content">
<main class="content">
<h1 id="response" class="title">Response</h1>
<p>A <a class="api" href="https://javadoc.io/doc/org.creativescala/krop-docs_3/latest/krop/route/Response.html">Response</a> describes how an HTTP response can be constructed from Scala values.</p>
<p>A <a class="api" href="https://javadoc.io/doc/org.creativescala/krop-docs_3/latest/krop/route/Response.html">Response</a> describes how a HTTP response can be constructed from Scala values. A response can be anything that implements the <code>Response</code> trait, but the usual way to call one of the constructors on the <a class="api" href="https://javadoc.io/doc/org.creativescala/krop-docs_3/latest/krop/route/Response$.html">Response</a> companion object. For example</p>
<pre><code class="nohighlight"><span class="keyword">val</span><span> </span><span class="identifier">response</span><span> = </span><span class="type-name">Response</span><span>.</span><span class="identifier">ok</span><span>(</span><span class="type-name">Entity</span><span>.</span><span class="identifier">html</span><span>)</span></code></pre>
<p>constructs a <code>Response</code> that responds with an HTTP OK, and an HTML entity constructed from a Scala <code>String</code>.</p>

</main>
<footer>Creative Scala is copyright Noel Welsh</footer>
Expand Down

0 comments on commit 3daff97

Please sign in to comment.