Skip to content

Commit

Permalink
auto commit on travis unfiltered/website@e908c85 21.1
Browse files Browse the repository at this point in the history
  • Loading branch information
unfiltered-bot committed Jun 10, 2017
1 parent bd205b0 commit e9f1e2e
Show file tree
Hide file tree
Showing 49 changed files with 11,349 additions and 0 deletions.
309 changes: 309 additions & 0 deletions 01.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,309 @@
<!DOCTYPE html>
<html class="no-js" lang="en">

<head>
<title>Try Unfiltered · Unfiltered</title>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta name="description" content='website'/>
<link href="https://fonts.googleapis.com/css?family=Roboto:100normal,100italic,300normal,300italic,400normal,400italic,500normal,500italic,700normal,700italic,900normal,900italicc" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="lib/jquery/jquery.min.js"></script>
<script type="text/javascript" src="js/page.js"></script>
<link rel="stylesheet" type="text/css" href="lib/normalize.css/normalize.css"/>
<link rel="stylesheet" type="text/css" href="lib/foundation/dist/foundation.min.css"/>
<link rel="stylesheet" type="text/css" href="css/page.css"/>

<!--
<link rel="shortcut icon" href="images/favicon.ico" />
-->
</head>

<body>
<div class="off-canvas-wrapper">
<div class="off-canvas-wrapper-inner" data-off-canvas-wrapper>

<div class="off-canvas position-left" id="off-canvas-menu" data-off-canvas>
<nav class="off-canvas-nav">
<div class="nav-home">
<a href="index.html" >
<span class="home-icon"></span>Unfiltered
</a>
<div class="version-number">
0.9.1
</div>
</div>
<div class="nav-toc">
<ul>
<li><a href="01.html" class="active">Try Unfiltered</a></li>
<li><a href="02.html">Plans and Intents</a></li>
<li><a href="03.html">Bindings and Servers</a></li>
<li><a href="04.html">Project Setup</a></li>
<li><a href="05.html">Community</a></li>
<li><a href="06/00.html">Matching and Responding</a>
<ul>
<li><a href="06/a.html">Request Matchers</a></li>
<li><a href="06/b.html">Within the Parameters</a></li>
<li><a href="06/c.html">Response Functions</a></li>
<li><a href="06/d.html">Silly Store</a></li>
</ul></li>
<li><a href="07/00.html">Directives and Validation</a>
<ul>
<li><a href="07/a.html">Directive Intent</a></li>
<li><a href="07/b.html">Parameters as Directives</a></li>
<li><a href="07/c.html">Interpreter Reuse and Implicits</a></li>
<li><a href="07/d.html">Required Parameters</a></li>
<li><a href="07/e.html">Independent Failure</a></li>
<li><a href="07/f.html">Interpreters of Your Own Design</a></li>
<li><a href="07/g.html">Let&rsquo;s wrap this up, Ada</a></li>
</ul></li>
<li><a href="08/00.html">Application Structure</a>
<ul>
<li><a href="08/a.html">Planning for Any-thing</a></li>
<li><a href="08/b.html">Just Kitting</a></li>
</ul></li>
<li><a href="09/00.html">Identification and Cookies</a>
<ul>
<li><a href="09/a.html">Who&rsquo;s Who</a></li>
<li><a href="09/b.html">Remembrance of Things Past</a></li>
</ul></li>
<li><a href="10/00.html">Netty Plans</a>
<ul>
<li><a href="10/a.html">Trying Netty</a></li>
<li><a href="10/b.html">Execution and Exceptions</a></li>
<li><a href="10/c.html">Chunked Requests</a></li>
<li><a href="10/d.html">Going Asynchronous</a></li>
<li><a href="10/e.html">Asyncrazy Temperature Server</a></li>
</ul></li>
<li><a href="11.html">Jetty Extras</a></li>
<li><a href="12.html">ScalaTest</a></li>
<li><a href="99.html">Who&rsquo;s Using Unfiltered?</a></li>
</ul>
</div>

</nav>
</div>

<div class="off-canvas-content" data-off-canvas-content>

<header class="site-header expanded row">
<div class="small-12 column">
<a href="#" class="off-canvas-toggle hide-for-medium" data-toggle="off-canvas-menu"><svg class="svg-icon svg-icon-menu" version="1.1" id="Menu" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 20 20" enable-background="new 0 0 20 20" xml:space="preserve"> <path class="svg-icon-menu-path" fill="#53CDEC" d="M16.4,9H3.6C3.048,9,3,9.447,3,10c0,0.553,0.048,1,0.6,1H16.4c0.552,0,0.6-0.447,0.6-1C17,9.447,16.952,9,16.4,9z M16.4,13
H3.6C3.048,13,3,13.447,3,14c0,0.553,0.048,1,0.6,1H16.4c0.552,0,0.6-0.447,0.6-1C17,13.447,16.952,13,16.4,13z M3.6,7H16.4
C16.952,7,17,6.553,17,6c0-0.553-0.048-1-0.6-1H3.6C3.048,5,3,5.447,3,6C3,6.553,3.048,7,3.6,7z"/></svg>
</a>
<div class="title"><a href="index.html">Unfiltered</a></div>

<!--
<a href="https://www.example.com" class="logo show-for-medium">logo</a>
-->
</div>
</header>

<div class="expanded row">

<div class="medium-3 large-2 show-for-medium column">
<nav class="site-nav">
<div class="nav-home">
<a href="index.html" >
<span class="home-icon"></span>Unfiltered
</a>
<div class="version-number">
0.9.1
</div>
</div>
<div class="nav-toc">
<ul>
<li><a href="01.html" class="active">Try Unfiltered</a></li>
<li><a href="02.html">Plans and Intents</a></li>
<li><a href="03.html">Bindings and Servers</a></li>
<li><a href="04.html">Project Setup</a></li>
<li><a href="05.html">Community</a></li>
<li><a href="06/00.html">Matching and Responding</a>
<ul>
<li><a href="06/a.html">Request Matchers</a></li>
<li><a href="06/b.html">Within the Parameters</a></li>
<li><a href="06/c.html">Response Functions</a></li>
<li><a href="06/d.html">Silly Store</a></li>
</ul></li>
<li><a href="07/00.html">Directives and Validation</a>
<ul>
<li><a href="07/a.html">Directive Intent</a></li>
<li><a href="07/b.html">Parameters as Directives</a></li>
<li><a href="07/c.html">Interpreter Reuse and Implicits</a></li>
<li><a href="07/d.html">Required Parameters</a></li>
<li><a href="07/e.html">Independent Failure</a></li>
<li><a href="07/f.html">Interpreters of Your Own Design</a></li>
<li><a href="07/g.html">Let&rsquo;s wrap this up, Ada</a></li>
</ul></li>
<li><a href="08/00.html">Application Structure</a>
<ul>
<li><a href="08/a.html">Planning for Any-thing</a></li>
<li><a href="08/b.html">Just Kitting</a></li>
</ul></li>
<li><a href="09/00.html">Identification and Cookies</a>
<ul>
<li><a href="09/a.html">Who&rsquo;s Who</a></li>
<li><a href="09/b.html">Remembrance of Things Past</a></li>
</ul></li>
<li><a href="10/00.html">Netty Plans</a>
<ul>
<li><a href="10/a.html">Trying Netty</a></li>
<li><a href="10/b.html">Execution and Exceptions</a></li>
<li><a href="10/c.html">Chunked Requests</a></li>
<li><a href="10/d.html">Going Asynchronous</a></li>
<li><a href="10/e.html">Asyncrazy Temperature Server</a></li>
</ul></li>
<li><a href="11.html">Jetty Extras</a></li>
<li><a href="12.html">ScalaTest</a></li>
<li><a href="99.html">Who&rsquo;s Using Unfiltered?</a></li>
</ul>
</div>

</nav>
</div>

<div class="small-12 medium-9 large-10 column">
<section class="site-content">

<div class="page-header row">
<div class="medium-12 show-for-medium column">
<div class="nav-breadcrumbs">
<ul>
<li><a href="index.html">Unfiltered</a></li>
<li>Try Unfiltered</li>
</ul>
</div>
</div>
</div>

<div class="page-content row">
<div class="small-12 large-9 column" id="docs">
<h2><a href="#try-unfiltered" name="try-unfiltered" class="anchor"><span class="anchor-link"></span></a>Try Unfiltered</h2>
<p>It&rsquo;s not hard to write a request handler in the Scala console using Unfiltered. The tricky part is getting everything on the classpath.</p>
<h3><a href="#play-project" name="play-project" class="anchor"><span class="anchor-link"></span></a>Play Project</h3>
<p>The approach recommended here uses <a href="https://github.com/foundweekends/giter8#readme">giter8</a>, a tool for setting up projects based on templates stored in github. Assuming you don&rsquo;t have giter8 installed and you are on a network-connected Linux or Mac, it&rsquo;s easy to fix that.</p>
<pre class="prettyprint"><code class="language-sh">curl https://raw.githubusercontent.com/foundweekends/conscript/master/setup.sh | sh
</code></pre>
<p>That is <a href="https://github.com/foundweekends/conscript#readme">conscript</a>. Its <code>setup.sh</code> places a permanent (assuming you don&rsquo;t delete it) executable script in <code>~/bin/cs</code>. At some point you may want to add <code>~/bin</code> to your executable search path, but these instructions will not assume it is.</p>
<pre class="prettyprint"><code class="language-sh">~/bin/cs foundweekends/giter8
</code></pre>
<p>That installs a <code>g8</code>. Now you have a script to run giter8. The next step creates a sbt project under the current working directory.</p>
<pre class="prettyprint"><code class="language-sh">~/bin/g8 unfiltered/unfiltered --name=justplayin
</code></pre>
<p>Okay, finally we can use this project with sbt to get a console for Unfiltered. You do have <a href="http://www.scala-sbt.org/">sbt setup</a>, don&rsquo;t you?</p>
<pre class="prettyprint"><code class="language-sh">cd justplayin
sbt console
</code></pre>
<h3><a href="#consoled" name="consoled" class="anchor"><span class="anchor-link"></span></a>Consoled</h3>
<p>Now that you have a <code>scala&gt;</code> prompt with the <code>unfiltered-filter</code> and <code>unfiltered-jetty</code> modules on the classpath, let&rsquo;s have some fun.</p>
<pre class="prettyprint"><code class="language-scala">import unfiltered.request._
import unfiltered.response._

val echo = unfiltered.filter.Planify {
case Path(Seg(p :: Nil)) =&gt; ResponseString(p)
}</code></pre>
<p>This filter <code>echo</code> would work with any servlet container. We can use it in a Jetty server right now.</p>
<pre class="prettyprint"><code class="language-scala">unfiltered.jetty.Server.anylocal.plan(echo).run()</code></pre>
<p>The startup message tells you which open port was selected, and by default it is only listening to requests from 127.0.0.1. So on the same machine, you can make requests to your server. e.g.</p>
<pre class="prettyprint"><code class="language-sh">curl http://127.0.0.1:&lt;the right port&gt;/hello+world
</code></pre>
<p>Fancy desktop web browsers will work too. Notice that exactly one path segment is required for the filter to respond to the request. If you ask for the root path or a deeper path, the <code>echo</code> filter will not handle the request and Jetty responds with a 404 page.</p>
<p>If we want to handle any request, we could broaden the pattern matching expression. (Press enter to stop the running server.)</p>
<pre class="prettyprint"><code class="language-scala">val echoNice = unfiltered.filter.Planify {
case Path(Seg(p :: Nil)) =&gt; ResponseString(p)
case _ =&gt; ResponseString(
&quot;I can echo exactly one path element.&quot;
)
}
unfiltered.jetty.Server.anylocal.plan(echoNice).run()</code></pre>
<p>Or we could define another filter chain it to the first.</p>
<pre class="prettyprint"><code class="language-scala">val nice = unfiltered.filter.Planify {
case _ =&gt; ResponseString(
&quot;I can echo exactly one path element.&quot;
)
}
unfiltered.jetty.Server.anylocal.plan(echo).plan(nice).run()</code></pre>
<p>Happy now?</p>
<div class="nav-next">
<p><strong>Next:</strong> <a href="02.html">Plans and Intents</a></p>
</div>
</div>
<div class="large-3 show-for-large column" data-sticky-container>
<nav class="sidebar sticky" data-sticky data-anchor="docs" data-sticky-on="large">
<div class="page-nav">
<div class="nav-title">On this page:</div>
<div class="nav-toc">
<ul>
<li><a href="01.html#try-unfiltered">Try Unfiltered</a>
<ul>
<li><a href="01.html#play-project">Play Project</a></li>
<li><a href="01.html#consoled">Consoled</a></li>
</ul></li>
</ul>
</div>
</div>
</nav>
</div>
</div>

</section>
</div>

</div>

<footer class="site-footer">

<section class="site-footer-nav">
<div class="expanded row">
<div class="small-12 large-offset-2 large-10 column">
<div class="row site-footer-content">

<div class="small-12 medium-4 large-3 text-center column">
<div class="nav-links">
<ul>
<!-- <li><a href="https://www.example.com/products/">Products</a> -->
</ul>
</div>
</div>

</div>
</div>
</div>
</section>

<section class="site-footer-base">
<div class="expanded row">
<div class="small-12 large-offset-2 large-10 column">
<div class="row site-footer-content">

<div class="small-12 text-center large-9 column">

<!--
<div class="copyright">
<span class="text">&copy; 2017</span>
<a href="https://www.example.com" class="logo">logo</a>
</div>
-->
</div>

</div>
</div>
</div>
</section>
</footer>

</div>
</div>
</div>
</body>

<script type="text/javascript" src="lib/foundation/dist/foundation.min.js"></script>
<script type="text/javascript">jQuery(document).foundation();</script>
<script type="text/javascript" src="js/magellan.js"></script>

<style type="text/css">@import "lib/prettify/prettify.css";</style>
<script type="text/javascript" src="lib/prettify/prettify.js"></script>
<script type="text/javascript" src="lib/prettify/lang-scala.js"></script>
<script type="text/javascript">jQuery(function(){window.prettyPrint && prettyPrint()});</script>

</html>
Loading

0 comments on commit e9f1e2e

Please sign in to comment.