mirror of
https://github.com/metosin/reitit.git
synced 2025-12-30 05:08:25 +00:00
Build book from commit 095dfb6724 [skip ci]
This commit is contained in:
parent
627454fb84
commit
aed32e89fd
19 changed files with 2193 additions and 278 deletions
|
|
@ -60,7 +60,7 @@
|
|||
<link rel="next" href="../ring/" />
|
||||
|
||||
|
||||
<link rel="prev" href="route_validation.html" />
|
||||
<link rel="prev" href="different_routers.html" />
|
||||
|
||||
|
||||
</head>
|
||||
|
|
@ -181,12 +181,12 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.2.6" data-path="../basics/different_routers.html">
|
||||
<li class="chapter " data-level="1.2.6" data-path="../basics/route_conflicts.html">
|
||||
|
||||
<a href="../basics/different_routers.html">
|
||||
<a href="../basics/route_conflicts.html">
|
||||
|
||||
|
||||
Different Routers
|
||||
Route conflicts
|
||||
|
||||
</a>
|
||||
|
||||
|
|
@ -213,12 +213,12 @@
|
|||
<ul class="articles">
|
||||
|
||||
|
||||
<li class="chapter " data-level="1.3.1" data-path="route_conflicts.html">
|
||||
<li class="chapter " data-level="1.3.1" data-path="route_validation.html">
|
||||
|
||||
<a href="route_conflicts.html">
|
||||
<a href="route_validation.html">
|
||||
|
||||
|
||||
Route conflicts
|
||||
Route Validation
|
||||
|
||||
</a>
|
||||
|
||||
|
|
@ -226,12 +226,12 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.3.2" data-path="route_validation.html">
|
||||
<li class="chapter " data-level="1.3.2" data-path="different_routers.html">
|
||||
|
||||
<a href="route_validation.html">
|
||||
<a href="different_routers.html">
|
||||
|
||||
|
||||
Route Validation
|
||||
Different Routers
|
||||
|
||||
</a>
|
||||
|
||||
|
|
@ -297,7 +297,20 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.3" data-path="../ring/parameter_coercion.html">
|
||||
<li class="chapter " data-level="1.4.3" data-path="../ring/data_driven_middleware.html">
|
||||
|
||||
<a href="../ring/data_driven_middleware.html">
|
||||
|
||||
|
||||
Data-driven Middleware
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.4" data-path="../ring/parameter_coercion.html">
|
||||
|
||||
<a href="../ring/parameter_coercion.html">
|
||||
|
||||
|
|
@ -310,7 +323,7 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.4" data-path="../ring/compiling_middleware.html">
|
||||
<li class="chapter " data-level="1.4.5" data-path="../ring/compiling_middleware.html">
|
||||
|
||||
<a href="../ring/compiling_middleware.html">
|
||||
|
||||
|
|
@ -470,7 +483,7 @@
|
|||
|
||||
|
||||
|
||||
<a href="route_validation.html" class="navigation navigation-prev " aria-label="Previous page: Route Validation">
|
||||
<a href="different_routers.html" class="navigation navigation-prev " aria-label="Previous page: Different Routers">
|
||||
<i class="fa fa-angle-left"></i>
|
||||
</a>
|
||||
|
||||
|
|
@ -486,7 +499,7 @@
|
|||
<script>
|
||||
var gitbook = gitbook || [];
|
||||
gitbook.push(function() {
|
||||
gitbook.page.hasChanged({"page":{"title":"Configuring routers","level":"1.3.3","depth":2,"next":{"title":"Ring","level":"1.4","depth":1,"path":"ring/README.md","ref":"ring/README.md","articles":[{"title":"Ring-router","level":"1.4.1","depth":2,"path":"ring/ring.md","ref":"ring/ring.md","articles":[]},{"title":"Dynamic extensions","level":"1.4.2","depth":2,"path":"ring/dynamic_extensions.md","ref":"ring/dynamic_extensions.md","articles":[]},{"title":"Parameter coercion","level":"1.4.3","depth":2,"path":"ring/parameter_coercion.md","ref":"ring/parameter_coercion.md","articles":[]},{"title":"Compiling middleware","level":"1.4.4","depth":2,"path":"ring/compiling_middleware.md","ref":"ring/compiling_middleware.md","articles":[]}]},"previous":{"title":"Route Validation","level":"1.3.2","depth":2,"path":"advanced/route_validation.md","ref":"advanced/route_validation.md","articles":[]},"dir":"ltr"},"config":{"plugins":["editlink","github","highlight"],"root":"doc","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"editlink":{"label":"Edit This Page","multilingual":false,"base":"https://github.com/metosin/reitit/tree/master/doc"},"github":{"url":"https://github.com/metosin/reitit"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"gitbook":"*"},"file":{"path":"advanced/configuring_routers.md","mtime":"2017-10-29T07:29:44.989Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2017-10-29T07:30:20.667Z"},"basePath":"..","book":{"language":""}});
|
||||
gitbook.page.hasChanged({"page":{"title":"Configuring routers","level":"1.3.3","depth":2,"next":{"title":"Ring","level":"1.4","depth":1,"path":"ring/README.md","ref":"ring/README.md","articles":[{"title":"Ring-router","level":"1.4.1","depth":2,"path":"ring/ring.md","ref":"ring/ring.md","articles":[]},{"title":"Dynamic extensions","level":"1.4.2","depth":2,"path":"ring/dynamic_extensions.md","ref":"ring/dynamic_extensions.md","articles":[]},{"title":"Data-driven Middleware","level":"1.4.3","depth":2,"path":"ring/data_driven_middleware.md","ref":"ring/data_driven_middleware.md","articles":[]},{"title":"Parameter coercion","level":"1.4.4","depth":2,"path":"ring/parameter_coercion.md","ref":"ring/parameter_coercion.md","articles":[]},{"title":"Compiling middleware","level":"1.4.5","depth":2,"path":"ring/compiling_middleware.md","ref":"ring/compiling_middleware.md","articles":[]}]},"previous":{"title":"Different Routers","level":"1.3.2","depth":2,"path":"advanced/different_routers.md","ref":"advanced/different_routers.md","articles":[]},"dir":"ltr"},"config":{"plugins":["editlink","github","highlight"],"root":"doc","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"editlink":{"label":"Edit This Page","multilingual":false,"base":"https://github.com/metosin/reitit/tree/master/doc"},"github":{"url":"https://github.com/metosin/reitit"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"gitbook":"*"},"file":{"path":"advanced/configuring_routers.md","mtime":"2017-10-31T08:26:00.327Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2017-10-31T08:26:38.332Z"},"basePath":"..","book":{"language":""}});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
|
|
|||
538
advanced/different_routers.html
Normal file
538
advanced/different_routers.html
Normal file
|
|
@ -0,0 +1,538 @@
|
|||
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="" >
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
||||
<title>Different Routers · GitBook</title>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="description" content="">
|
||||
<meta name="generator" content="GitBook 3.2.3">
|
||||
|
||||
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../gitbook/style.css">
|
||||
|
||||
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
|
||||
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
|
||||
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<meta name="HandheldFriendly" content="true"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black">
|
||||
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
|
||||
<link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
|
||||
|
||||
|
||||
<link rel="next" href="configuring_routers.html" />
|
||||
|
||||
|
||||
<link rel="prev" href="route_validation.html" />
|
||||
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="book">
|
||||
<div class="book-summary">
|
||||
|
||||
|
||||
<div id="book-search-input" role="search">
|
||||
<input type="text" placeholder="Type to search" />
|
||||
</div>
|
||||
|
||||
|
||||
<nav role="navigation">
|
||||
|
||||
|
||||
|
||||
<ul class="summary">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="chapter " data-level="1.1" data-path="../">
|
||||
|
||||
<a href="../">
|
||||
|
||||
|
||||
Introduction
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.2" data-path="../basics/">
|
||||
|
||||
<a href="../basics/">
|
||||
|
||||
|
||||
Basics
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
<ul class="articles">
|
||||
|
||||
|
||||
<li class="chapter " data-level="1.2.1" data-path="../basics/route_syntax.html">
|
||||
|
||||
<a href="../basics/route_syntax.html">
|
||||
|
||||
|
||||
Route syntax
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.2.2" data-path="../basics/router.html">
|
||||
|
||||
<a href="../basics/router.html">
|
||||
|
||||
|
||||
Router
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.2.3" data-path="../basics/path_based_routing.html">
|
||||
|
||||
<a href="../basics/path_based_routing.html">
|
||||
|
||||
|
||||
Path-based Routing
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.2.4" data-path="../basics/name_based_routing.html">
|
||||
|
||||
<a href="../basics/name_based_routing.html">
|
||||
|
||||
|
||||
Name-based Routing
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.2.5" data-path="../basics/route_data.html">
|
||||
|
||||
<a href="../basics/route_data.html">
|
||||
|
||||
|
||||
Route data
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.2.6" data-path="../basics/route_conflicts.html">
|
||||
|
||||
<a href="../basics/route_conflicts.html">
|
||||
|
||||
|
||||
Route conflicts
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.3" data-path="./">
|
||||
|
||||
<a href="./">
|
||||
|
||||
|
||||
Advanced
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
<ul class="articles">
|
||||
|
||||
|
||||
<li class="chapter " data-level="1.3.1" data-path="route_validation.html">
|
||||
|
||||
<a href="route_validation.html">
|
||||
|
||||
|
||||
Route Validation
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter active" data-level="1.3.2" data-path="different_routers.html">
|
||||
|
||||
<a href="different_routers.html">
|
||||
|
||||
|
||||
Different Routers
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.3.3" data-path="configuring_routers.html">
|
||||
|
||||
<a href="configuring_routers.html">
|
||||
|
||||
|
||||
Configuring routers
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4" data-path="../ring/">
|
||||
|
||||
<a href="../ring/">
|
||||
|
||||
|
||||
Ring
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
<ul class="articles">
|
||||
|
||||
|
||||
<li class="chapter " data-level="1.4.1" data-path="../ring/ring.html">
|
||||
|
||||
<a href="../ring/ring.html">
|
||||
|
||||
|
||||
Ring-router
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.2" data-path="../ring/dynamic_extensions.html">
|
||||
|
||||
<a href="../ring/dynamic_extensions.html">
|
||||
|
||||
|
||||
Dynamic extensions
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.3" data-path="../ring/data_driven_middleware.html">
|
||||
|
||||
<a href="../ring/data_driven_middleware.html">
|
||||
|
||||
|
||||
Data-driven Middleware
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.4" data-path="../ring/parameter_coercion.html">
|
||||
|
||||
<a href="../ring/parameter_coercion.html">
|
||||
|
||||
|
||||
Parameter coercion
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.5" data-path="../ring/compiling_middleware.html">
|
||||
|
||||
<a href="../ring/compiling_middleware.html">
|
||||
|
||||
|
||||
Compiling middleware
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.5" >
|
||||
|
||||
<span>
|
||||
|
||||
|
||||
TODO: Swagger & OpenAPI
|
||||
|
||||
</span>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.6" >
|
||||
|
||||
<span>
|
||||
|
||||
|
||||
TODO: Interceptors
|
||||
|
||||
</span>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="divider"></li>
|
||||
|
||||
<li>
|
||||
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">
|
||||
Published with GitBook
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
||||
</nav>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div class="book-body">
|
||||
|
||||
<div class="body-inner">
|
||||
|
||||
|
||||
|
||||
<div class="book-header" role="navigation">
|
||||
|
||||
|
||||
<!-- Title -->
|
||||
<h1>
|
||||
<i class="fa fa-circle-o-notch fa-spin"></i>
|
||||
<a href=".." >Different Routers</a>
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="page-wrapper" tabindex="-1" role="main">
|
||||
<div class="page-inner">
|
||||
|
||||
<div id="book-search-results">
|
||||
<div class="search-noresults">
|
||||
|
||||
<section class="normal markdown-section">
|
||||
|
||||
<h1 id="different-routers">Different Routers</h1>
|
||||
<p>Reitit ships with several different implementations for the <code>Router</code> protocol, originally based on the <a href="https://github.com/pedestal/pedestal/tree/master/route" target="_blank">Pedestal</a> implementation. <code>router</code> selects the most suitable implementation by inspecting the expanded routes. The implementation can be set manually using <code>:router</code> option, see <a href="advanced/configuring_routers.md">configuring routers</a>.</p>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>router</th>
|
||||
<th>description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><code>:linear-router</code></td>
|
||||
<td>Matches the routes one-by-one starting from the top until a match is found. Works with any kind of routes.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>:lookup-router</code></td>
|
||||
<td>Fast router, uses hash-lookup to resolve the route. Valid if no paths have path or catch-all parameters.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>:mixed-router</code></td>
|
||||
<td>Creates internally a <code>:linear-router</code> and a <code>:lookup-router</code> and used them to effectively get best-of-both-worlds. Valid if there are no <a href="../basics/route_conflicts.html">Route conflicts</a>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>::single-static-path-router</code></td>
|
||||
<td>Fastest possible router: valid only if there is one static route.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>:prefix-tree-router</code></td>
|
||||
<td>TODO: <a href="https://github.com/julienschmidt/httprouter#how-does-it-work" target="_blank">https://github.com/julienschmidt/httprouter#how-does-it-work</a></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>The router name can be asked from the router</p>
|
||||
<pre><code class="lang-clj">(<span class="hljs-name">r/router-name</span> router)
|
||||
<span class="hljs-comment">; :mixed-router</span>
|
||||
</code></pre>
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
</div>
|
||||
<div class="search-results">
|
||||
<div class="has-results">
|
||||
|
||||
<h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
|
||||
<ul class="search-results-list"></ul>
|
||||
|
||||
</div>
|
||||
<div class="no-results">
|
||||
|
||||
<h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<a href="route_validation.html" class="navigation navigation-prev " aria-label="Previous page: Route Validation">
|
||||
<i class="fa fa-angle-left"></i>
|
||||
</a>
|
||||
|
||||
|
||||
<a href="configuring_routers.html" class="navigation navigation-next " aria-label="Next page: Configuring routers">
|
||||
<i class="fa fa-angle-right"></i>
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var gitbook = gitbook || [];
|
||||
gitbook.push(function() {
|
||||
gitbook.page.hasChanged({"page":{"title":"Different Routers","level":"1.3.2","depth":2,"next":{"title":"Configuring routers","level":"1.3.3","depth":2,"path":"advanced/configuring_routers.md","ref":"advanced/configuring_routers.md","articles":[]},"previous":{"title":"Route Validation","level":"1.3.1","depth":2,"path":"advanced/route_validation.md","ref":"advanced/route_validation.md","articles":[]},"dir":"ltr"},"config":{"plugins":["editlink","github","highlight"],"root":"doc","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"editlink":{"label":"Edit This Page","multilingual":false,"base":"https://github.com/metosin/reitit/tree/master/doc"},"github":{"url":"https://github.com/metosin/reitit"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"gitbook":"*"},"file":{"path":"advanced/different_routers.md","mtime":"2017-10-31T08:26:00.327Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2017-10-31T08:26:38.332Z"},"basePath":"..","book":{"language":""}});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook.js"></script>
|
||||
<script src="../gitbook/theme.js"></script>
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook-plugin-editlink/plugin.js"></script>
|
||||
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook-plugin-github/plugin.js"></script>
|
||||
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
|
||||
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook-plugin-search/search.js"></script>
|
||||
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
|
||||
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
|
||||
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
|
||||
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
|
@ -57,10 +57,10 @@
|
|||
<link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
|
||||
|
||||
|
||||
<link rel="next" href="route_conflicts.html" />
|
||||
<link rel="next" href="route_validation.html" />
|
||||
|
||||
|
||||
<link rel="prev" href="../basics/different_routers.html" />
|
||||
<link rel="prev" href="../basics/route_conflicts.html" />
|
||||
|
||||
|
||||
</head>
|
||||
|
|
@ -181,12 +181,12 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.2.6" data-path="../basics/different_routers.html">
|
||||
<li class="chapter " data-level="1.2.6" data-path="../basics/route_conflicts.html">
|
||||
|
||||
<a href="../basics/different_routers.html">
|
||||
<a href="../basics/route_conflicts.html">
|
||||
|
||||
|
||||
Different Routers
|
||||
Route conflicts
|
||||
|
||||
</a>
|
||||
|
||||
|
|
@ -213,12 +213,12 @@
|
|||
<ul class="articles">
|
||||
|
||||
|
||||
<li class="chapter " data-level="1.3.1" data-path="route_conflicts.html">
|
||||
<li class="chapter " data-level="1.3.1" data-path="route_validation.html">
|
||||
|
||||
<a href="route_conflicts.html">
|
||||
<a href="route_validation.html">
|
||||
|
||||
|
||||
Route conflicts
|
||||
Route Validation
|
||||
|
||||
</a>
|
||||
|
||||
|
|
@ -226,12 +226,12 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.3.2" data-path="route_validation.html">
|
||||
<li class="chapter " data-level="1.3.2" data-path="different_routers.html">
|
||||
|
||||
<a href="route_validation.html">
|
||||
<a href="different_routers.html">
|
||||
|
||||
|
||||
Route Validation
|
||||
Different Routers
|
||||
|
||||
</a>
|
||||
|
||||
|
|
@ -297,7 +297,20 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.3" data-path="../ring/parameter_coercion.html">
|
||||
<li class="chapter " data-level="1.4.3" data-path="../ring/data_driven_middleware.html">
|
||||
|
||||
<a href="../ring/data_driven_middleware.html">
|
||||
|
||||
|
||||
Data-driven Middleware
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.4" data-path="../ring/parameter_coercion.html">
|
||||
|
||||
<a href="../ring/parameter_coercion.html">
|
||||
|
||||
|
|
@ -310,7 +323,7 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.4" data-path="../ring/compiling_middleware.html">
|
||||
<li class="chapter " data-level="1.4.5" data-path="../ring/compiling_middleware.html">
|
||||
|
||||
<a href="../ring/compiling_middleware.html">
|
||||
|
||||
|
|
@ -401,9 +414,9 @@
|
|||
|
||||
<h1 id="advanced">Advanced</h1>
|
||||
<ul>
|
||||
<li><a href="advanced/route_conflicts.md">Route conflicts</a></li>
|
||||
<li><a href="advanced/route_validation.md">Route Validation</a></li>
|
||||
<li><a href="advanced/configuring_routers.md">Configuring routers</a></li>
|
||||
<li><a href="route_validation.html">Route Validation</a></li>
|
||||
<li><a href="different_routers.html">Different Routers</a></li>
|
||||
<li><a href="configuring_routers.html">Configuring routers</a></li>
|
||||
</ul>
|
||||
|
||||
|
||||
|
|
@ -432,12 +445,12 @@
|
|||
|
||||
|
||||
|
||||
<a href="../basics/different_routers.html" class="navigation navigation-prev " aria-label="Previous page: Different Routers">
|
||||
<a href="../basics/route_conflicts.html" class="navigation navigation-prev " aria-label="Previous page: Route conflicts">
|
||||
<i class="fa fa-angle-left"></i>
|
||||
</a>
|
||||
|
||||
|
||||
<a href="route_conflicts.html" class="navigation navigation-next " aria-label="Next page: Route conflicts">
|
||||
<a href="route_validation.html" class="navigation navigation-next " aria-label="Next page: Route Validation">
|
||||
<i class="fa fa-angle-right"></i>
|
||||
</a>
|
||||
|
||||
|
|
@ -448,7 +461,7 @@
|
|||
<script>
|
||||
var gitbook = gitbook || [];
|
||||
gitbook.push(function() {
|
||||
gitbook.page.hasChanged({"page":{"title":"Advanced","level":"1.3","depth":1,"next":{"title":"Route conflicts","level":"1.3.1","depth":2,"path":"advanced/route_conflicts.md","ref":"advanced/route_conflicts.md","articles":[]},"previous":{"title":"Different Routers","level":"1.2.6","depth":2,"path":"basics/different_routers.md","ref":"basics/different_routers.md","articles":[]},"dir":"ltr"},"config":{"plugins":["editlink","github","highlight"],"root":"doc","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"editlink":{"label":"Edit This Page","multilingual":false,"base":"https://github.com/metosin/reitit/tree/master/doc"},"github":{"url":"https://github.com/metosin/reitit"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"gitbook":"*"},"file":{"path":"advanced/README.md","mtime":"2017-10-29T07:29:44.989Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2017-10-29T07:30:20.667Z"},"basePath":"..","book":{"language":""}});
|
||||
gitbook.page.hasChanged({"page":{"title":"Advanced","level":"1.3","depth":1,"next":{"title":"Route Validation","level":"1.3.1","depth":2,"path":"advanced/route_validation.md","ref":"advanced/route_validation.md","articles":[]},"previous":{"title":"Route conflicts","level":"1.2.6","depth":2,"path":"basics/route_conflicts.md","ref":"basics/route_conflicts.md","articles":[]},"dir":"ltr"},"config":{"plugins":["editlink","github","highlight"],"root":"doc","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"editlink":{"label":"Edit This Page","multilingual":false,"base":"https://github.com/metosin/reitit/tree/master/doc"},"github":{"url":"https://github.com/metosin/reitit"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"gitbook":"*"},"file":{"path":"advanced/README.md","mtime":"2017-10-31T08:26:00.327Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2017-10-31T08:26:38.332Z"},"basePath":"..","book":{"language":""}});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -57,10 +57,10 @@
|
|||
<link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
|
||||
|
||||
|
||||
<link rel="next" href="configuring_routers.html" />
|
||||
<link rel="next" href="different_routers.html" />
|
||||
|
||||
|
||||
<link rel="prev" href="route_conflicts.html" />
|
||||
<link rel="prev" href="./" />
|
||||
|
||||
|
||||
</head>
|
||||
|
|
@ -181,12 +181,12 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.2.6" data-path="../basics/different_routers.html">
|
||||
<li class="chapter " data-level="1.2.6" data-path="../basics/route_conflicts.html">
|
||||
|
||||
<a href="../basics/different_routers.html">
|
||||
<a href="../basics/route_conflicts.html">
|
||||
|
||||
|
||||
Different Routers
|
||||
Route conflicts
|
||||
|
||||
</a>
|
||||
|
||||
|
|
@ -213,12 +213,12 @@
|
|||
<ul class="articles">
|
||||
|
||||
|
||||
<li class="chapter " data-level="1.3.1" data-path="route_conflicts.html">
|
||||
<li class="chapter active" data-level="1.3.1" data-path="route_validation.html">
|
||||
|
||||
<a href="route_conflicts.html">
|
||||
<a href="route_validation.html">
|
||||
|
||||
|
||||
Route conflicts
|
||||
Route Validation
|
||||
|
||||
</a>
|
||||
|
||||
|
|
@ -226,12 +226,12 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter active" data-level="1.3.2" data-path="route_validation.html">
|
||||
<li class="chapter " data-level="1.3.2" data-path="different_routers.html">
|
||||
|
||||
<a href="route_validation.html">
|
||||
<a href="different_routers.html">
|
||||
|
||||
|
||||
Route Validation
|
||||
Different Routers
|
||||
|
||||
</a>
|
||||
|
||||
|
|
@ -297,7 +297,20 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.3" data-path="../ring/parameter_coercion.html">
|
||||
<li class="chapter " data-level="1.4.3" data-path="../ring/data_driven_middleware.html">
|
||||
|
||||
<a href="../ring/data_driven_middleware.html">
|
||||
|
||||
|
||||
Data-driven Middleware
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.4" data-path="../ring/parameter_coercion.html">
|
||||
|
||||
<a href="../ring/parameter_coercion.html">
|
||||
|
||||
|
|
@ -310,7 +323,7 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.4" data-path="../ring/compiling_middleware.html">
|
||||
<li class="chapter " data-level="1.4.5" data-path="../ring/compiling_middleware.html">
|
||||
|
||||
<a href="../ring/compiling_middleware.html">
|
||||
|
||||
|
|
@ -403,12 +416,11 @@
|
|||
<p>Namespace <code>reitit.spec</code> contains <a href="https://clojure.org/about/spec" target="_blank">clojure.spec</a> definitions for raw-routes, routes, router and router options.</p>
|
||||
<p><strong>NOTE:</strong> Use of specs requires to use one of the following:</p>
|
||||
<ul>
|
||||
<li><code>[org.clojure/clojurescript "1.9.660"]</code></li>
|
||||
<li><code>[org.clojure/clojure "1.9.0-alpha19"]</code></li>
|
||||
<li><code>[clojure-future-spec "1.9.0-alpha17"]</code> (Clojure 1.8)</li>
|
||||
<li><code>[org.clojure/clojurescript "1.9.660"]</code> (or higher)</li>
|
||||
<li><code>[org.clojure/clojure "1.9.0-beta2"]</code> (or higher)</li>
|
||||
<li><code>[clojure-future-spec "1.9.0-alpha17"]</code> (if Clojure 1.8 is used)</li>
|
||||
</ul>
|
||||
<h2 id="at-runtime">At runtime</h2>
|
||||
<p>If route trees are generated at runtime (e.g. from external source like the database), one can use directly the <code>clojure.spec</code> functions.</p>
|
||||
<h2 id="example">Example</h2>
|
||||
<pre><code class="lang-clj">(<span class="hljs-name">require</span> '[clojure.spec.alpha <span class="hljs-symbol">:as</span> s])
|
||||
(<span class="hljs-name">require</span> '[reitit.spec <span class="hljs-symbol">:as</span> spec])
|
||||
|
||||
|
|
@ -428,7 +440,7 @@
|
|||
<h2 id="at-development-time">At development time</h2>
|
||||
<p><code>reitit.core/router</code> can be instrumented and use something like <a href="https://github.com/bhb/expound" target="_blank">expound</a> to pretty-print the spec problems.</p>
|
||||
<p>First add a <code>:dev</code> dependency to:</p>
|
||||
<pre><code class="lang-clj">[expound <span class="hljs-string">"0.3.0"</span>]
|
||||
<pre><code class="lang-clj">[expound <span class="hljs-string">"0.3.0"</span>] <span class="hljs-comment">; or higher</span>
|
||||
</code></pre>
|
||||
<p>Some bootstrapping:</p>
|
||||
<pre><code class="lang-clj">(<span class="hljs-name">require</span> '[clojure.spec.test.alpha <span class="hljs-symbol">:as</span> stest])
|
||||
|
|
@ -440,8 +452,9 @@
|
|||
(<span class="hljs-name"><span class="hljs-builtin-name">set!</span></span> s/*explain-out* expound/printer)
|
||||
</code></pre>
|
||||
<p>And we are ready to go:</p>
|
||||
<pre><code class="lang-clj">
|
||||
(<span class="hljs-name">reitit/router</span>
|
||||
<pre><code class="lang-clj">(<span class="hljs-name">require</span> '[reitit.core <span class="hljs-symbol">:as</span> r])
|
||||
|
||||
(<span class="hljs-name">r/router</span>
|
||||
[<span class="hljs-string">"/api"</span>
|
||||
[<span class="hljs-string">"/public"</span>
|
||||
[<span class="hljs-string">"/ping"</span>]
|
||||
|
|
@ -581,12 +594,12 @@
|
|||
|
||||
|
||||
|
||||
<a href="route_conflicts.html" class="navigation navigation-prev " aria-label="Previous page: Route conflicts">
|
||||
<a href="./" class="navigation navigation-prev " aria-label="Previous page: Advanced">
|
||||
<i class="fa fa-angle-left"></i>
|
||||
</a>
|
||||
|
||||
|
||||
<a href="configuring_routers.html" class="navigation navigation-next " aria-label="Next page: Configuring routers">
|
||||
<a href="different_routers.html" class="navigation navigation-next " aria-label="Next page: Different Routers">
|
||||
<i class="fa fa-angle-right"></i>
|
||||
</a>
|
||||
|
||||
|
|
@ -597,7 +610,7 @@
|
|||
<script>
|
||||
var gitbook = gitbook || [];
|
||||
gitbook.push(function() {
|
||||
gitbook.page.hasChanged({"page":{"title":"Route Validation","level":"1.3.2","depth":2,"next":{"title":"Configuring routers","level":"1.3.3","depth":2,"path":"advanced/configuring_routers.md","ref":"advanced/configuring_routers.md","articles":[]},"previous":{"title":"Route conflicts","level":"1.3.1","depth":2,"path":"advanced/route_conflicts.md","ref":"advanced/route_conflicts.md","articles":[]},"dir":"ltr"},"config":{"plugins":["editlink","github","highlight"],"root":"doc","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"editlink":{"label":"Edit This Page","multilingual":false,"base":"https://github.com/metosin/reitit/tree/master/doc"},"github":{"url":"https://github.com/metosin/reitit"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"gitbook":"*"},"file":{"path":"advanced/route_validation.md","mtime":"2017-10-29T07:29:44.989Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2017-10-29T07:30:20.667Z"},"basePath":"..","book":{"language":""}});
|
||||
gitbook.page.hasChanged({"page":{"title":"Route Validation","level":"1.3.1","depth":2,"next":{"title":"Different Routers","level":"1.3.2","depth":2,"path":"advanced/different_routers.md","ref":"advanced/different_routers.md","articles":[]},"previous":{"title":"Advanced","level":"1.3","depth":1,"path":"advanced/README.md","ref":"advanced/README.md","articles":[{"title":"Route Validation","level":"1.3.1","depth":2,"path":"advanced/route_validation.md","ref":"advanced/route_validation.md","articles":[]},{"title":"Different Routers","level":"1.3.2","depth":2,"path":"advanced/different_routers.md","ref":"advanced/different_routers.md","articles":[]},{"title":"Configuring routers","level":"1.3.3","depth":2,"path":"advanced/configuring_routers.md","ref":"advanced/configuring_routers.md","articles":[]}]},"dir":"ltr"},"config":{"plugins":["editlink","github","highlight"],"root":"doc","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"editlink":{"label":"Edit This Page","multilingual":false,"base":"https://github.com/metosin/reitit/tree/master/doc"},"github":{"url":"https://github.com/metosin/reitit"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"gitbook":"*"},"file":{"path":"advanced/route_validation.md","mtime":"2017-10-31T08:26:00.327Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2017-10-31T08:26:38.332Z"},"basePath":"..","book":{"language":""}});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -181,12 +181,12 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.2.6" data-path="different_routers.html">
|
||||
<li class="chapter " data-level="1.2.6" data-path="route_conflicts.html">
|
||||
|
||||
<a href="different_routers.html">
|
||||
<a href="route_conflicts.html">
|
||||
|
||||
|
||||
Different Routers
|
||||
Route conflicts
|
||||
|
||||
</a>
|
||||
|
||||
|
|
@ -213,12 +213,12 @@
|
|||
<ul class="articles">
|
||||
|
||||
|
||||
<li class="chapter " data-level="1.3.1" data-path="../advanced/route_conflicts.html">
|
||||
<li class="chapter " data-level="1.3.1" data-path="../advanced/route_validation.html">
|
||||
|
||||
<a href="../advanced/route_conflicts.html">
|
||||
<a href="../advanced/route_validation.html">
|
||||
|
||||
|
||||
Route conflicts
|
||||
Route Validation
|
||||
|
||||
</a>
|
||||
|
||||
|
|
@ -226,12 +226,12 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.3.2" data-path="../advanced/route_validation.html">
|
||||
<li class="chapter " data-level="1.3.2" data-path="../advanced/different_routers.html">
|
||||
|
||||
<a href="../advanced/route_validation.html">
|
||||
<a href="../advanced/different_routers.html">
|
||||
|
||||
|
||||
Route Validation
|
||||
Different Routers
|
||||
|
||||
</a>
|
||||
|
||||
|
|
@ -297,7 +297,20 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.3" data-path="../ring/parameter_coercion.html">
|
||||
<li class="chapter " data-level="1.4.3" data-path="../ring/data_driven_middleware.html">
|
||||
|
||||
<a href="../ring/data_driven_middleware.html">
|
||||
|
||||
|
||||
Data-driven Middleware
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.4" data-path="../ring/parameter_coercion.html">
|
||||
|
||||
<a href="../ring/parameter_coercion.html">
|
||||
|
||||
|
|
@ -310,7 +323,7 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.4" data-path="../ring/compiling_middleware.html">
|
||||
<li class="chapter " data-level="1.4.5" data-path="../ring/compiling_middleware.html">
|
||||
|
||||
<a href="../ring/compiling_middleware.html">
|
||||
|
||||
|
|
@ -401,12 +414,12 @@
|
|||
|
||||
<h1 id="basics">Basics</h1>
|
||||
<ul>
|
||||
<li><a href="basics/route_syntax.md">Route syntax</a></li>
|
||||
<li><a href="basics/router.md">Router</a></li>
|
||||
<li><a href="basics/path_based_routing.md">Path-based Routing</a></li>
|
||||
<li><a href="basics/name_based_routing.md">Name-based Routing</a></li>
|
||||
<li><a href="basics/route_data.md">Route data</a></li>
|
||||
<li><a href="basics/different_routers.md">Different Routers</a></li>
|
||||
<li><a href="route_syntax.html">Route syntax</a></li>
|
||||
<li><a href="router.html">Router</a></li>
|
||||
<li><a href="path_based_routing.html">Path-based Routing</a></li>
|
||||
<li><a href="name_based_routing.html">Name-based Routing</a></li>
|
||||
<li><a href="route_data.html">Route data</a></li>
|
||||
<li><a href="route_conflicts.html">Route conflicts</a></li>
|
||||
</ul>
|
||||
|
||||
|
||||
|
|
@ -451,7 +464,7 @@
|
|||
<script>
|
||||
var gitbook = gitbook || [];
|
||||
gitbook.push(function() {
|
||||
gitbook.page.hasChanged({"page":{"title":"Basics","level":"1.2","depth":1,"next":{"title":"Route syntax","level":"1.2.1","depth":2,"path":"basics/route_syntax.md","ref":"basics/route_syntax.md","articles":[]},"previous":{"title":"Introduction","level":"1.1","depth":1,"path":"README.md","ref":"README.md","articles":[]},"dir":"ltr"},"config":{"plugins":["editlink","github","highlight"],"root":"doc","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"editlink":{"label":"Edit This Page","multilingual":false,"base":"https://github.com/metosin/reitit/tree/master/doc"},"github":{"url":"https://github.com/metosin/reitit"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"gitbook":"*"},"file":{"path":"basics/README.md","mtime":"2017-10-29T07:29:44.989Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2017-10-29T07:30:20.667Z"},"basePath":"..","book":{"language":""}});
|
||||
gitbook.page.hasChanged({"page":{"title":"Basics","level":"1.2","depth":1,"next":{"title":"Route syntax","level":"1.2.1","depth":2,"path":"basics/route_syntax.md","ref":"basics/route_syntax.md","articles":[]},"previous":{"title":"Introduction","level":"1.1","depth":1,"path":"README.md","ref":"README.md","articles":[]},"dir":"ltr"},"config":{"plugins":["editlink","github","highlight"],"root":"doc","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"editlink":{"label":"Edit This Page","multilingual":false,"base":"https://github.com/metosin/reitit/tree/master/doc"},"github":{"url":"https://github.com/metosin/reitit"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"gitbook":"*"},"file":{"path":"basics/README.md","mtime":"2017-10-31T08:26:00.327Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2017-10-31T08:26:38.332Z"},"basePath":"..","book":{"language":""}});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -181,12 +181,12 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.2.6" data-path="different_routers.html">
|
||||
<li class="chapter " data-level="1.2.6" data-path="route_conflicts.html">
|
||||
|
||||
<a href="different_routers.html">
|
||||
<a href="route_conflicts.html">
|
||||
|
||||
|
||||
Different Routers
|
||||
Route conflicts
|
||||
|
||||
</a>
|
||||
|
||||
|
|
@ -213,12 +213,12 @@
|
|||
<ul class="articles">
|
||||
|
||||
|
||||
<li class="chapter " data-level="1.3.1" data-path="../advanced/route_conflicts.html">
|
||||
<li class="chapter " data-level="1.3.1" data-path="../advanced/route_validation.html">
|
||||
|
||||
<a href="../advanced/route_conflicts.html">
|
||||
<a href="../advanced/route_validation.html">
|
||||
|
||||
|
||||
Route conflicts
|
||||
Route Validation
|
||||
|
||||
</a>
|
||||
|
||||
|
|
@ -226,12 +226,12 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.3.2" data-path="../advanced/route_validation.html">
|
||||
<li class="chapter " data-level="1.3.2" data-path="../advanced/different_routers.html">
|
||||
|
||||
<a href="../advanced/route_validation.html">
|
||||
<a href="../advanced/different_routers.html">
|
||||
|
||||
|
||||
Route Validation
|
||||
Different Routers
|
||||
|
||||
</a>
|
||||
|
||||
|
|
@ -297,7 +297,20 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.3" data-path="../ring/parameter_coercion.html">
|
||||
<li class="chapter " data-level="1.4.3" data-path="../ring/data_driven_middleware.html">
|
||||
|
||||
<a href="../ring/data_driven_middleware.html">
|
||||
|
||||
|
||||
Data-driven Middleware
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.4" data-path="../ring/parameter_coercion.html">
|
||||
|
||||
<a href="../ring/parameter_coercion.html">
|
||||
|
||||
|
|
@ -310,7 +323,7 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.4" data-path="../ring/compiling_middleware.html">
|
||||
<li class="chapter " data-level="1.4.5" data-path="../ring/compiling_middleware.html">
|
||||
|
||||
<a href="../ring/compiling_middleware.html">
|
||||
|
||||
|
|
@ -399,13 +412,34 @@
|
|||
|
||||
<section class="normal markdown-section">
|
||||
|
||||
<h2 id="name-based-routing">Name-based routing</h2>
|
||||
<p>All routes which <code>:name</code> route data defined, can be matched by name.</p>
|
||||
<h2 id="name-based-reverse-routing">Name-based (reverse) routing</h2>
|
||||
<p>All routes which have <code>:name</code> route data defined, can also be matched by name.</p>
|
||||
<p>Given a router:</p>
|
||||
<pre><code class="lang-clj">(<span class="hljs-name">require</span> '[reitit.core <span class="hljs-symbol">:as</span> r])
|
||||
|
||||
(<span class="hljs-name"><span class="hljs-builtin-name">def</span></span> router
|
||||
(<span class="hljs-name">r/router</span>
|
||||
[[<span class="hljs-string">"/api"</span>
|
||||
[<span class="hljs-string">"/ping"</span> <span class="hljs-symbol">::ping</span>]
|
||||
[<span class="hljs-string">"/user/:id"</span> <span class="hljs-symbol">::user</span>]]]))
|
||||
</code></pre>
|
||||
<p>Listing all route names:</p>
|
||||
<pre><code class="lang-clj">(<span class="hljs-name">r/route-names</span> router)
|
||||
<span class="hljs-comment">; [:user/ping :user/user]</span>
|
||||
</code></pre>
|
||||
<p>Matching by name:</p>
|
||||
<p>No match returns <code>nil</code>:</p>
|
||||
<pre><code class="lang-clj">(<span class="hljs-name">r/match-by-name</span> router <span class="hljs-symbol">::kikka</span>)
|
||||
<span class="hljs-literal">nil</span>
|
||||
</code></pre>
|
||||
<p>Matching a route:</p>
|
||||
<pre><code class="lang-clj">(<span class="hljs-name">r/match-by-name</span> router <span class="hljs-symbol">::ping</span>)
|
||||
<span class="hljs-comment">; #Match{:template "/api/ping"</span>
|
||||
<span class="hljs-comment">; :meta {:name :user/ping}</span>
|
||||
<span class="hljs-comment">; :result nil</span>
|
||||
<span class="hljs-comment">; :params {}</span>
|
||||
<span class="hljs-comment">; :path "/api/ping"}</span>
|
||||
</code></pre>
|
||||
<p>If not all path-parameters are set, a <code>PartialMatch</code> is returned:</p>
|
||||
<pre><code class="lang-clj">(<span class="hljs-name">r/match-by-name</span> router <span class="hljs-symbol">::user</span>)
|
||||
<span class="hljs-comment">; #PartialMatch{:template "/api/user/:id",</span>
|
||||
<span class="hljs-comment">; :meta {:name :user/user},</span>
|
||||
|
|
@ -416,7 +450,7 @@
|
|||
(<span class="hljs-name">r/partial-match?</span> (<span class="hljs-name">r/match-by-name</span> router <span class="hljs-symbol">::user</span>))
|
||||
<span class="hljs-comment">; true</span>
|
||||
</code></pre>
|
||||
<p>We only got a partial match as we didn't provide the needed path-parameters. Let's provide the them too:</p>
|
||||
<p>With provided path-parameters:</p>
|
||||
<pre><code class="lang-clj">(<span class="hljs-name">r/match-by-name</span> router <span class="hljs-symbol">::user</span> {<span class="hljs-symbol">:id</span> <span class="hljs-string">"1"</span>})
|
||||
<span class="hljs-comment">; #Match{:template "/api/user/:id"</span>
|
||||
<span class="hljs-comment">; :meta {:name :user/user}</span>
|
||||
|
|
@ -471,7 +505,7 @@
|
|||
<script>
|
||||
var gitbook = gitbook || [];
|
||||
gitbook.push(function() {
|
||||
gitbook.page.hasChanged({"page":{"title":"Name-based Routing","level":"1.2.4","depth":2,"next":{"title":"Route data","level":"1.2.5","depth":2,"path":"basics/route_data.md","ref":"basics/route_data.md","articles":[]},"previous":{"title":"Path-based Routing","level":"1.2.3","depth":2,"path":"basics/path_based_routing.md","ref":"basics/path_based_routing.md","articles":[]},"dir":"ltr"},"config":{"plugins":["editlink","github","highlight"],"root":"doc","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"editlink":{"label":"Edit This Page","multilingual":false,"base":"https://github.com/metosin/reitit/tree/master/doc"},"github":{"url":"https://github.com/metosin/reitit"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"gitbook":"*"},"file":{"path":"basics/name_based_routing.md","mtime":"2017-10-29T07:29:44.989Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2017-10-29T07:30:20.667Z"},"basePath":"..","book":{"language":""}});
|
||||
gitbook.page.hasChanged({"page":{"title":"Name-based Routing","level":"1.2.4","depth":2,"next":{"title":"Route data","level":"1.2.5","depth":2,"path":"basics/route_data.md","ref":"basics/route_data.md","articles":[]},"previous":{"title":"Path-based Routing","level":"1.2.3","depth":2,"path":"basics/path_based_routing.md","ref":"basics/path_based_routing.md","articles":[]},"dir":"ltr"},"config":{"plugins":["editlink","github","highlight"],"root":"doc","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"editlink":{"label":"Edit This Page","multilingual":false,"base":"https://github.com/metosin/reitit/tree/master/doc"},"github":{"url":"https://github.com/metosin/reitit"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"gitbook":"*"},"file":{"path":"basics/name_based_routing.md","mtime":"2017-10-31T08:26:00.331Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2017-10-31T08:26:38.332Z"},"basePath":"..","book":{"language":""}});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -181,12 +181,12 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.2.6" data-path="different_routers.html">
|
||||
<li class="chapter " data-level="1.2.6" data-path="route_conflicts.html">
|
||||
|
||||
<a href="different_routers.html">
|
||||
<a href="route_conflicts.html">
|
||||
|
||||
|
||||
Different Routers
|
||||
Route conflicts
|
||||
|
||||
</a>
|
||||
|
||||
|
|
@ -213,12 +213,12 @@
|
|||
<ul class="articles">
|
||||
|
||||
|
||||
<li class="chapter " data-level="1.3.1" data-path="../advanced/route_conflicts.html">
|
||||
<li class="chapter " data-level="1.3.1" data-path="../advanced/route_validation.html">
|
||||
|
||||
<a href="../advanced/route_conflicts.html">
|
||||
<a href="../advanced/route_validation.html">
|
||||
|
||||
|
||||
Route conflicts
|
||||
Route Validation
|
||||
|
||||
</a>
|
||||
|
||||
|
|
@ -226,12 +226,12 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.3.2" data-path="../advanced/route_validation.html">
|
||||
<li class="chapter " data-level="1.3.2" data-path="../advanced/different_routers.html">
|
||||
|
||||
<a href="../advanced/route_validation.html">
|
||||
<a href="../advanced/different_routers.html">
|
||||
|
||||
|
||||
Route Validation
|
||||
Different Routers
|
||||
|
||||
</a>
|
||||
|
||||
|
|
@ -297,7 +297,20 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.3" data-path="../ring/parameter_coercion.html">
|
||||
<li class="chapter " data-level="1.4.3" data-path="../ring/data_driven_middleware.html">
|
||||
|
||||
<a href="../ring/data_driven_middleware.html">
|
||||
|
||||
|
||||
Data-driven Middleware
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.4" data-path="../ring/parameter_coercion.html">
|
||||
|
||||
<a href="../ring/parameter_coercion.html">
|
||||
|
||||
|
|
@ -310,7 +323,7 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.4" data-path="../ring/compiling_middleware.html">
|
||||
<li class="chapter " data-level="1.4.5" data-path="../ring/compiling_middleware.html">
|
||||
|
||||
<a href="../ring/compiling_middleware.html">
|
||||
|
||||
|
|
@ -406,9 +419,20 @@
|
|||
<li><code>PartialMatch</code>, path matched, missing path-parameters (only in reverse-routing)</li>
|
||||
<li><code>Match</code>, exact match</li>
|
||||
</ul>
|
||||
<p>Given a router:</p>
|
||||
<pre><code class="lang-clj">(<span class="hljs-name">require</span> '[reitit.core <span class="hljs-symbol">:as</span> r])
|
||||
|
||||
(<span class="hljs-name"><span class="hljs-builtin-name">def</span></span> router
|
||||
(<span class="hljs-name">r/router</span>
|
||||
[[<span class="hljs-string">"/api"</span>
|
||||
[<span class="hljs-string">"/ping"</span> <span class="hljs-symbol">::ping</span>]
|
||||
[<span class="hljs-string">"/user/:id"</span> <span class="hljs-symbol">::user</span>]]]))
|
||||
</code></pre>
|
||||
<p>No match returns <code>nil</code>:</p>
|
||||
<pre><code class="lang-clj">(<span class="hljs-name">r/match-by-path</span> router <span class="hljs-string">"/hello"</span>)
|
||||
<span class="hljs-comment">; nil</span>
|
||||
</code></pre>
|
||||
<p>Match provides the route information:</p>
|
||||
<pre><code class="lang-clj">(<span class="hljs-name">r/match-by-path</span> router <span class="hljs-string">"/api/user/1"</span>)
|
||||
<span class="hljs-comment">; #Match{:template "/api/user/:id"</span>
|
||||
<span class="hljs-comment">; :meta {:name :user/user}</span>
|
||||
|
|
@ -459,7 +483,7 @@
|
|||
<script>
|
||||
var gitbook = gitbook || [];
|
||||
gitbook.push(function() {
|
||||
gitbook.page.hasChanged({"page":{"title":"Path-based Routing","level":"1.2.3","depth":2,"next":{"title":"Name-based Routing","level":"1.2.4","depth":2,"path":"basics/name_based_routing.md","ref":"basics/name_based_routing.md","articles":[]},"previous":{"title":"Router","level":"1.2.2","depth":2,"path":"basics/router.md","ref":"basics/router.md","articles":[]},"dir":"ltr"},"config":{"plugins":["editlink","github","highlight"],"root":"doc","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"editlink":{"label":"Edit This Page","multilingual":false,"base":"https://github.com/metosin/reitit/tree/master/doc"},"github":{"url":"https://github.com/metosin/reitit"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"gitbook":"*"},"file":{"path":"basics/path_based_routing.md","mtime":"2017-10-29T07:29:44.989Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2017-10-29T07:30:20.667Z"},"basePath":"..","book":{"language":""}});
|
||||
gitbook.page.hasChanged({"page":{"title":"Path-based Routing","level":"1.2.3","depth":2,"next":{"title":"Name-based Routing","level":"1.2.4","depth":2,"path":"basics/name_based_routing.md","ref":"basics/name_based_routing.md","articles":[]},"previous":{"title":"Router","level":"1.2.2","depth":2,"path":"basics/router.md","ref":"basics/router.md","articles":[]},"dir":"ltr"},"config":{"plugins":["editlink","github","highlight"],"root":"doc","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"editlink":{"label":"Edit This Page","multilingual":false,"base":"https://github.com/metosin/reitit/tree/master/doc"},"github":{"url":"https://github.com/metosin/reitit"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"gitbook":"*"},"file":{"path":"basics/path_based_routing.md","mtime":"2017-10-31T08:26:00.331Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2017-10-31T08:26:38.332Z"},"basePath":"..","book":{"language":""}});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
|
|
|||
547
basics/route_conflicts.html
Normal file
547
basics/route_conflicts.html
Normal file
|
|
@ -0,0 +1,547 @@
|
|||
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="" >
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
||||
<title>Route conflicts · GitBook</title>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="description" content="">
|
||||
<meta name="generator" content="GitBook 3.2.3">
|
||||
|
||||
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../gitbook/style.css">
|
||||
|
||||
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
|
||||
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
|
||||
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<meta name="HandheldFriendly" content="true"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black">
|
||||
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
|
||||
<link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
|
||||
|
||||
|
||||
<link rel="next" href="../advanced/" />
|
||||
|
||||
|
||||
<link rel="prev" href="route_data.html" />
|
||||
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="book">
|
||||
<div class="book-summary">
|
||||
|
||||
|
||||
<div id="book-search-input" role="search">
|
||||
<input type="text" placeholder="Type to search" />
|
||||
</div>
|
||||
|
||||
|
||||
<nav role="navigation">
|
||||
|
||||
|
||||
|
||||
<ul class="summary">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="chapter " data-level="1.1" data-path="../">
|
||||
|
||||
<a href="../">
|
||||
|
||||
|
||||
Introduction
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.2" data-path="./">
|
||||
|
||||
<a href="./">
|
||||
|
||||
|
||||
Basics
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
<ul class="articles">
|
||||
|
||||
|
||||
<li class="chapter " data-level="1.2.1" data-path="route_syntax.html">
|
||||
|
||||
<a href="route_syntax.html">
|
||||
|
||||
|
||||
Route syntax
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.2.2" data-path="router.html">
|
||||
|
||||
<a href="router.html">
|
||||
|
||||
|
||||
Router
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.2.3" data-path="path_based_routing.html">
|
||||
|
||||
<a href="path_based_routing.html">
|
||||
|
||||
|
||||
Path-based Routing
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.2.4" data-path="name_based_routing.html">
|
||||
|
||||
<a href="name_based_routing.html">
|
||||
|
||||
|
||||
Name-based Routing
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.2.5" data-path="route_data.html">
|
||||
|
||||
<a href="route_data.html">
|
||||
|
||||
|
||||
Route data
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter active" data-level="1.2.6" data-path="route_conflicts.html">
|
||||
|
||||
<a href="route_conflicts.html">
|
||||
|
||||
|
||||
Route conflicts
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.3" data-path="../advanced/">
|
||||
|
||||
<a href="../advanced/">
|
||||
|
||||
|
||||
Advanced
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
<ul class="articles">
|
||||
|
||||
|
||||
<li class="chapter " data-level="1.3.1" data-path="../advanced/route_validation.html">
|
||||
|
||||
<a href="../advanced/route_validation.html">
|
||||
|
||||
|
||||
Route Validation
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.3.2" data-path="../advanced/different_routers.html">
|
||||
|
||||
<a href="../advanced/different_routers.html">
|
||||
|
||||
|
||||
Different Routers
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.3.3" data-path="../advanced/configuring_routers.html">
|
||||
|
||||
<a href="../advanced/configuring_routers.html">
|
||||
|
||||
|
||||
Configuring routers
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4" data-path="../ring/">
|
||||
|
||||
<a href="../ring/">
|
||||
|
||||
|
||||
Ring
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
<ul class="articles">
|
||||
|
||||
|
||||
<li class="chapter " data-level="1.4.1" data-path="../ring/ring.html">
|
||||
|
||||
<a href="../ring/ring.html">
|
||||
|
||||
|
||||
Ring-router
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.2" data-path="../ring/dynamic_extensions.html">
|
||||
|
||||
<a href="../ring/dynamic_extensions.html">
|
||||
|
||||
|
||||
Dynamic extensions
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.3" data-path="../ring/data_driven_middleware.html">
|
||||
|
||||
<a href="../ring/data_driven_middleware.html">
|
||||
|
||||
|
||||
Data-driven Middleware
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.4" data-path="../ring/parameter_coercion.html">
|
||||
|
||||
<a href="../ring/parameter_coercion.html">
|
||||
|
||||
|
||||
Parameter coercion
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.5" data-path="../ring/compiling_middleware.html">
|
||||
|
||||
<a href="../ring/compiling_middleware.html">
|
||||
|
||||
|
||||
Compiling middleware
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.5" >
|
||||
|
||||
<span>
|
||||
|
||||
|
||||
TODO: Swagger & OpenAPI
|
||||
|
||||
</span>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.6" >
|
||||
|
||||
<span>
|
||||
|
||||
|
||||
TODO: Interceptors
|
||||
|
||||
</span>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="divider"></li>
|
||||
|
||||
<li>
|
||||
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">
|
||||
Published with GitBook
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
||||
</nav>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div class="book-body">
|
||||
|
||||
<div class="body-inner">
|
||||
|
||||
|
||||
|
||||
<div class="book-header" role="navigation">
|
||||
|
||||
|
||||
<!-- Title -->
|
||||
<h1>
|
||||
<i class="fa fa-circle-o-notch fa-spin"></i>
|
||||
<a href=".." >Route conflicts</a>
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="page-wrapper" tabindex="-1" role="main">
|
||||
<div class="page-inner">
|
||||
|
||||
<div id="book-search-results">
|
||||
<div class="search-noresults">
|
||||
|
||||
<section class="normal markdown-section">
|
||||
|
||||
<h1 id="route-conflicts">Route conflicts</h1>
|
||||
<p>Many routing libraries allow multiple matches for a single path lookup. Usually, the first match is used and the rest are effecively unreachanle. This is not good, especially if route tree is merged from multiple sources.</p>
|
||||
<p>Reitit resolves this by running explicit conflicit resolution when a <code>router</code> is called. Conflicting routes are passed into a <code>:conflicts</code> callback. Default implementation throws <code>ex-info</code> with a descriptive message.</p>
|
||||
<p>Examples router with conflicting routes:</p>
|
||||
<pre><code class="lang-clj">(<span class="hljs-name">require</span> '[reitit.core <span class="hljs-symbol">:as</span> r])
|
||||
|
||||
(<span class="hljs-name"><span class="hljs-builtin-name">def</span></span> routes
|
||||
[[<span class="hljs-string">"/ping"</span>]
|
||||
[<span class="hljs-string">"/:user-id/orders"</span>]
|
||||
[<span class="hljs-string">"/bulk/:bulk-id"</span>]
|
||||
[<span class="hljs-string">"/public/*path"</span>]
|
||||
[<span class="hljs-string">"/:version/status"</span>]])
|
||||
</code></pre>
|
||||
<p>By default, <code>ExceptionInfo</code> is thrown:</p>
|
||||
<pre><code class="lang-clj">(<span class="hljs-name">r/router</span> routes)
|
||||
<span class="hljs-comment">; CompilerException clojure.lang.ExceptionInfo: Router contains conflicting routes:</span>
|
||||
<span class="hljs-comment">;</span>
|
||||
<span class="hljs-comment">; /:user-id/orders</span>
|
||||
<span class="hljs-comment">; -> /public/*path</span>
|
||||
<span class="hljs-comment">; -> /bulk/:bulk-id</span>
|
||||
<span class="hljs-comment">;</span>
|
||||
<span class="hljs-comment">; /bulk/:bulk-id</span>
|
||||
<span class="hljs-comment">; -> /:version/status</span>
|
||||
<span class="hljs-comment">;</span>
|
||||
<span class="hljs-comment">; /public/*path</span>
|
||||
<span class="hljs-comment">; -> /:version/status</span>
|
||||
<span class="hljs-comment">;</span>
|
||||
</code></pre>
|
||||
<p>Just logging the conflicts:</p>
|
||||
<pre><code class="lang-clj">(<span class="hljs-name">r/router</span>
|
||||
routes
|
||||
{<span class="hljs-symbol">:conflicts</span> (<span class="hljs-name"><span class="hljs-builtin-name">comp</span></span> println reitit/conflicts-str)})
|
||||
<span class="hljs-comment">; Router contains conflicting routes:</span>
|
||||
<span class="hljs-comment">;</span>
|
||||
<span class="hljs-comment">; /:user-id/orders</span>
|
||||
<span class="hljs-comment">; -> /public/*path</span>
|
||||
<span class="hljs-comment">; -> /bulk/:bulk-id</span>
|
||||
<span class="hljs-comment">;</span>
|
||||
<span class="hljs-comment">; /bulk/:bulk-id</span>
|
||||
<span class="hljs-comment">; -> /:version/status</span>
|
||||
<span class="hljs-comment">;</span>
|
||||
<span class="hljs-comment">; /public/*path</span>
|
||||
<span class="hljs-comment">; -> /:version/status</span>
|
||||
<span class="hljs-comment">;</span>
|
||||
</code></pre>
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
</div>
|
||||
<div class="search-results">
|
||||
<div class="has-results">
|
||||
|
||||
<h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
|
||||
<ul class="search-results-list"></ul>
|
||||
|
||||
</div>
|
||||
<div class="no-results">
|
||||
|
||||
<h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<a href="route_data.html" class="navigation navigation-prev " aria-label="Previous page: Route data">
|
||||
<i class="fa fa-angle-left"></i>
|
||||
</a>
|
||||
|
||||
|
||||
<a href="../advanced/" class="navigation navigation-next " aria-label="Next page: Advanced">
|
||||
<i class="fa fa-angle-right"></i>
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var gitbook = gitbook || [];
|
||||
gitbook.push(function() {
|
||||
gitbook.page.hasChanged({"page":{"title":"Route conflicts","level":"1.2.6","depth":2,"next":{"title":"Advanced","level":"1.3","depth":1,"path":"advanced/README.md","ref":"advanced/README.md","articles":[{"title":"Route Validation","level":"1.3.1","depth":2,"path":"advanced/route_validation.md","ref":"advanced/route_validation.md","articles":[]},{"title":"Different Routers","level":"1.3.2","depth":2,"path":"advanced/different_routers.md","ref":"advanced/different_routers.md","articles":[]},{"title":"Configuring routers","level":"1.3.3","depth":2,"path":"advanced/configuring_routers.md","ref":"advanced/configuring_routers.md","articles":[]}]},"previous":{"title":"Route data","level":"1.2.5","depth":2,"path":"basics/route_data.md","ref":"basics/route_data.md","articles":[]},"dir":"ltr"},"config":{"plugins":["editlink","github","highlight"],"root":"doc","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"editlink":{"label":"Edit This Page","multilingual":false,"base":"https://github.com/metosin/reitit/tree/master/doc"},"github":{"url":"https://github.com/metosin/reitit"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"gitbook":"*"},"file":{"path":"basics/route_conflicts.md","mtime":"2017-10-31T08:26:00.331Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2017-10-31T08:26:38.332Z"},"basePath":"..","book":{"language":""}});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook.js"></script>
|
||||
<script src="../gitbook/theme.js"></script>
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook-plugin-editlink/plugin.js"></script>
|
||||
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook-plugin-github/plugin.js"></script>
|
||||
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
|
||||
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook-plugin-search/search.js"></script>
|
||||
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
|
||||
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
|
||||
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
|
||||
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
|
@ -57,7 +57,7 @@
|
|||
<link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
|
||||
|
||||
|
||||
<link rel="next" href="different_routers.html" />
|
||||
<link rel="next" href="route_conflicts.html" />
|
||||
|
||||
|
||||
<link rel="prev" href="name_based_routing.html" />
|
||||
|
|
@ -181,12 +181,12 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.2.6" data-path="different_routers.html">
|
||||
<li class="chapter " data-level="1.2.6" data-path="route_conflicts.html">
|
||||
|
||||
<a href="different_routers.html">
|
||||
<a href="route_conflicts.html">
|
||||
|
||||
|
||||
Different Routers
|
||||
Route conflicts
|
||||
|
||||
</a>
|
||||
|
||||
|
|
@ -213,12 +213,12 @@
|
|||
<ul class="articles">
|
||||
|
||||
|
||||
<li class="chapter " data-level="1.3.1" data-path="../advanced/route_conflicts.html">
|
||||
<li class="chapter " data-level="1.3.1" data-path="../advanced/route_validation.html">
|
||||
|
||||
<a href="../advanced/route_conflicts.html">
|
||||
<a href="../advanced/route_validation.html">
|
||||
|
||||
|
||||
Route conflicts
|
||||
Route Validation
|
||||
|
||||
</a>
|
||||
|
||||
|
|
@ -226,12 +226,12 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.3.2" data-path="../advanced/route_validation.html">
|
||||
<li class="chapter " data-level="1.3.2" data-path="../advanced/different_routers.html">
|
||||
|
||||
<a href="../advanced/route_validation.html">
|
||||
<a href="../advanced/different_routers.html">
|
||||
|
||||
|
||||
Route Validation
|
||||
Different Routers
|
||||
|
||||
</a>
|
||||
|
||||
|
|
@ -297,7 +297,20 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.3" data-path="../ring/parameter_coercion.html">
|
||||
<li class="chapter " data-level="1.4.3" data-path="../ring/data_driven_middleware.html">
|
||||
|
||||
<a href="../ring/data_driven_middleware.html">
|
||||
|
||||
|
||||
Data-driven Middleware
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.4" data-path="../ring/parameter_coercion.html">
|
||||
|
||||
<a href="../ring/parameter_coercion.html">
|
||||
|
||||
|
|
@ -310,7 +323,7 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.4" data-path="../ring/compiling_middleware.html">
|
||||
<li class="chapter " data-level="1.4.5" data-path="../ring/compiling_middleware.html">
|
||||
|
||||
<a href="../ring/compiling_middleware.html">
|
||||
|
||||
|
|
@ -400,7 +413,40 @@
|
|||
<section class="normal markdown-section">
|
||||
|
||||
<h1 id="route-data">Route data</h1>
|
||||
<p>Routes can have arbitrary meta-data, interpreted by the router (via it's <code>:compile</code> hook) or the application itself. For nested routes, route data is accumulated recursively using <a href="https://github.com/weavejester/meta-merge" target="_blank">meta-merge</a>. By default, it appends collections, but it can be overridden to do <code>:prepend</code>, <code>:replace</code> or <code>:displace</code>.</p>
|
||||
<p>Route data is the heart of this library. Routes can have any data attachted to them. Data is interpeted either by the client application or the <code>Router</code> via it's <code>:coerce</code> and <code>:compile</code> hooks. This enables co-existence of both <a href="https://youtu.be/x9pxbnFC4aQ?t=1907" target="_blank">adaptive and principled</a> components.</p>
|
||||
<p>Routes can have a non-sequential route argument that is expanded into route data map when a router is created.</p>
|
||||
<pre><code class="lang-clj">(<span class="hljs-name">require</span> '[reitit.core <span class="hljs-symbol">:as</span> r])
|
||||
|
||||
(<span class="hljs-name"><span class="hljs-builtin-name">def</span></span> router
|
||||
(<span class="hljs-name">r/router</span>
|
||||
[[<span class="hljs-string">"/ping"</span> <span class="hljs-symbol">::ping</span>]
|
||||
[<span class="hljs-string">"/pong"</span> identity]
|
||||
[<span class="hljs-string">"/users"</span> {<span class="hljs-symbol">:get</span> {<span class="hljs-symbol">:roles</span> #{<span class="hljs-symbol">:admin</span>}
|
||||
<span class="hljs-symbol">:handler</span> identity}}]]))
|
||||
</code></pre>
|
||||
<p>The expanded route data can be retrieved from a router with <code>routes</code> and is returned with <code>match-by-path</code> and <code>match-by-name</code> in case of a route match.</p>
|
||||
<pre><code class="lang-clj">(<span class="hljs-name">r/routes</span> router)
|
||||
<span class="hljs-comment">; [["/ping" {:name :user/ping}]</span>
|
||||
<span class="hljs-comment">; ["/pong" {:handler identity]}</span>
|
||||
<span class="hljs-comment">; ["/users" {:get {:roles #{:admin}</span>
|
||||
<span class="hljs-comment">; :handler identity}}]]</span>
|
||||
|
||||
(<span class="hljs-name">r/match-by-path</span> router <span class="hljs-string">"/ping"</span>)
|
||||
<span class="hljs-comment">; #Match{:template "/ping"</span>
|
||||
<span class="hljs-comment">; :meta {:name :user/ping}</span>
|
||||
<span class="hljs-comment">; :result nil</span>
|
||||
<span class="hljs-comment">; :params {}</span>
|
||||
<span class="hljs-comment">; :path "/ping"}</span>
|
||||
|
||||
(<span class="hljs-name">r/match-by-name</span> router <span class="hljs-symbol">::ping</span>)
|
||||
<span class="hljs-comment">; #Match{:template "/ping"</span>
|
||||
<span class="hljs-comment">; :meta {:name :user/ping}</span>
|
||||
<span class="hljs-comment">; :result nil</span>
|
||||
<span class="hljs-comment">; :params {}</span>
|
||||
<span class="hljs-comment">; :path "/ping"}</span>
|
||||
</code></pre>
|
||||
<h2 id="nested-route-data">Nested route data</h2>
|
||||
<p>For nested route trees, route data is accumulated recursively from root towards leafs using <a href="https://github.com/weavejester/meta-merge" target="_blank">meta-merge</a>. Default behavior for colections is <code>:append</code>, but this can be overridden to <code>:prepend</code>, <code>:replace</code> or <code>:displace</code> using the target meta-data.</p>
|
||||
<p>An example router with nested data:</p>
|
||||
<pre><code class="lang-clj">(<span class="hljs-name"><span class="hljs-builtin-name">def</span></span> router
|
||||
(<span class="hljs-name">r/router</span>
|
||||
|
|
@ -409,37 +455,41 @@
|
|||
[<span class="hljs-string">"/admin"</span> {<span class="hljs-symbol">:roles</span> #{<span class="hljs-symbol">:admin</span>}}
|
||||
[<span class="hljs-string">"/users"</span> <span class="hljs-symbol">::users</span>]
|
||||
[<span class="hljs-string">"/db"</span> {<span class="hljs-symbol">:interceptors</span> [<span class="hljs-symbol">::db</span>]
|
||||
<span class="hljs-symbol">:roles</span> ^<span class="hljs-symbol">:replace</span> #{<span class="hljs-symbol">:db-admin</span>}}
|
||||
[<span class="hljs-string">"/:db"</span> {<span class="hljs-symbol">:parameters</span> {<span class="hljs-symbol">:db</span> String}}
|
||||
[<span class="hljs-string">"/drop"</span> <span class="hljs-symbol">::drop-db</span>]
|
||||
[<span class="hljs-string">"/stats"</span> <span class="hljs-symbol">::db-stats</span>]]]]]))
|
||||
<span class="hljs-symbol">:roles</span> ^<span class="hljs-symbol">:replace</span> #{<span class="hljs-symbol">:db-admin</span>}}]]]))
|
||||
</code></pre>
|
||||
<p>Resolved route tree:</p>
|
||||
<pre><code class="lang-clj">(<span class="hljs-name">reitit/routes</span> router)
|
||||
<pre><code class="lang-clj">(<span class="hljs-name">r/routes</span> router)
|
||||
<span class="hljs-comment">; [["/api/ping" {:interceptors [::api]</span>
|
||||
<span class="hljs-comment">; :name ::ping}]</span>
|
||||
<span class="hljs-comment">; :name :user/ping}]</span>
|
||||
<span class="hljs-comment">; ["/api/admin/users" {:interceptors [::api]</span>
|
||||
<span class="hljs-comment">; :roles #{:admin}</span>
|
||||
<span class="hljs-comment">; :name ::users}]</span>
|
||||
<span class="hljs-comment">; ["/api/admin/db/:db/drop" {:interceptors [::api ::db]</span>
|
||||
<span class="hljs-comment">; :roles #{:db-admin}</span>
|
||||
<span class="hljs-comment">; :parameters {:db String}</span>
|
||||
<span class="hljs-comment">; :name ::drop-db}]</span>
|
||||
<span class="hljs-comment">; ["/api/admin/db/:db/stats" {:interceptors [::api ::db]</span>
|
||||
<span class="hljs-comment">; :roles #{:db-admin}</span>
|
||||
<span class="hljs-comment">; :parameters {:db String}</span>
|
||||
<span class="hljs-comment">; :name ::db-stats}]]</span>
|
||||
<span class="hljs-comment">; :name ::users} nil]</span>
|
||||
<span class="hljs-comment">; ["/api/admin/db" {:interceptors [::api ::db]</span>
|
||||
<span class="hljs-comment">; :roles #{:db-admin}}]]</span>
|
||||
</code></pre>
|
||||
<p>Route data is returned with <code>Match</code> and the application can act based on it.</p>
|
||||
<pre><code class="lang-clj">(<span class="hljs-name">r/match-by-path</span> router <span class="hljs-string">"/api/admin/db/users/drop"</span>)
|
||||
<span class="hljs-comment">; #Match{:template "/api/admin/db/:db/drop"</span>
|
||||
<span class="hljs-comment">; :meta {:interceptors [::api ::db]</span>
|
||||
<span class="hljs-comment">; :roles #{:db-admin}</span>
|
||||
<span class="hljs-comment">; :parameters {:db String}</span>
|
||||
<span class="hljs-comment">; :name ::drop-db}</span>
|
||||
<h2 id="expansion">Expansion</h2>
|
||||
<p>By default, <code>reitit/Expand</code> protocol is used to expand the route arguments. It expands keywords into <code>:name</code> and functions into <code>:handler</code> key in the route data map. It's easy to add custom expanders and one can chenge the whole expand implementation via <a href="../advanced/configuring_routers.html">router options</a>.</p>
|
||||
<pre><code class="lang-clj">(<span class="hljs-name">require</span> '[reitit.core <span class="hljs-symbol">:as</span> r])
|
||||
|
||||
(<span class="hljs-name"><span class="hljs-builtin-name">def</span></span> router
|
||||
(<span class="hljs-name">r/router</span>
|
||||
[[<span class="hljs-string">"/ping"</span> <span class="hljs-symbol">::ping</span>]
|
||||
[<span class="hljs-string">"/pong"</span> identity]
|
||||
[<span class="hljs-string">"/users"</span> {<span class="hljs-symbol">:get</span> {<span class="hljs-symbol">:roles</span> #{<span class="hljs-symbol">:admin</span>}
|
||||
<span class="hljs-symbol">:handler</span> identity}}]]))
|
||||
|
||||
(<span class="hljs-name">r/routes</span> router)
|
||||
<span class="hljs-comment">; [["/ping" {:name :user/ping}]</span>
|
||||
<span class="hljs-comment">; ["/pong" {:handler identity]}</span>
|
||||
<span class="hljs-comment">; ["/users" {:get {:roles #{:admin}</span>
|
||||
<span class="hljs-comment">; :handler identity}}]]</span>
|
||||
|
||||
(<span class="hljs-name">r/match-by-path</span> router <span class="hljs-string">"/ping"</span>)
|
||||
<span class="hljs-comment">; #Match{:template "/ping"</span>
|
||||
<span class="hljs-comment">; :meta {:name :user/ping}</span>
|
||||
<span class="hljs-comment">; :result nil</span>
|
||||
<span class="hljs-comment">; :params {:db "users"}</span>
|
||||
<span class="hljs-comment">; :path "/api/admin/db/users/drop"}</span>
|
||||
<span class="hljs-comment">; :params {}</span>
|
||||
<span class="hljs-comment">; :path "/ping"}</span>
|
||||
</code></pre>
|
||||
|
||||
|
||||
|
|
@ -473,7 +523,7 @@
|
|||
</a>
|
||||
|
||||
|
||||
<a href="different_routers.html" class="navigation navigation-next " aria-label="Next page: Different Routers">
|
||||
<a href="route_conflicts.html" class="navigation navigation-next " aria-label="Next page: Route conflicts">
|
||||
<i class="fa fa-angle-right"></i>
|
||||
</a>
|
||||
|
||||
|
|
@ -484,7 +534,7 @@
|
|||
<script>
|
||||
var gitbook = gitbook || [];
|
||||
gitbook.push(function() {
|
||||
gitbook.page.hasChanged({"page":{"title":"Route data","level":"1.2.5","depth":2,"next":{"title":"Different Routers","level":"1.2.6","depth":2,"path":"basics/different_routers.md","ref":"basics/different_routers.md","articles":[]},"previous":{"title":"Name-based Routing","level":"1.2.4","depth":2,"path":"basics/name_based_routing.md","ref":"basics/name_based_routing.md","articles":[]},"dir":"ltr"},"config":{"plugins":["editlink","github","highlight"],"root":"doc","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"editlink":{"label":"Edit This Page","multilingual":false,"base":"https://github.com/metosin/reitit/tree/master/doc"},"github":{"url":"https://github.com/metosin/reitit"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"gitbook":"*"},"file":{"path":"basics/route_data.md","mtime":"2017-10-29T07:29:44.989Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2017-10-29T07:30:20.667Z"},"basePath":"..","book":{"language":""}});
|
||||
gitbook.page.hasChanged({"page":{"title":"Route data","level":"1.2.5","depth":2,"next":{"title":"Route conflicts","level":"1.2.6","depth":2,"path":"basics/route_conflicts.md","ref":"basics/route_conflicts.md","articles":[]},"previous":{"title":"Name-based Routing","level":"1.2.4","depth":2,"path":"basics/name_based_routing.md","ref":"basics/name_based_routing.md","articles":[]},"dir":"ltr"},"config":{"plugins":["editlink","github","highlight"],"root":"doc","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"editlink":{"label":"Edit This Page","multilingual":false,"base":"https://github.com/metosin/reitit/tree/master/doc"},"github":{"url":"https://github.com/metosin/reitit"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"gitbook":"*"},"file":{"path":"basics/route_data.md","mtime":"2017-10-31T08:26:00.331Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2017-10-31T08:26:38.332Z"},"basePath":"..","book":{"language":""}});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -181,12 +181,12 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.2.6" data-path="different_routers.html">
|
||||
<li class="chapter " data-level="1.2.6" data-path="route_conflicts.html">
|
||||
|
||||
<a href="different_routers.html">
|
||||
<a href="route_conflicts.html">
|
||||
|
||||
|
||||
Different Routers
|
||||
Route conflicts
|
||||
|
||||
</a>
|
||||
|
||||
|
|
@ -213,12 +213,12 @@
|
|||
<ul class="articles">
|
||||
|
||||
|
||||
<li class="chapter " data-level="1.3.1" data-path="../advanced/route_conflicts.html">
|
||||
<li class="chapter " data-level="1.3.1" data-path="../advanced/route_validation.html">
|
||||
|
||||
<a href="../advanced/route_conflicts.html">
|
||||
<a href="../advanced/route_validation.html">
|
||||
|
||||
|
||||
Route conflicts
|
||||
Route Validation
|
||||
|
||||
</a>
|
||||
|
||||
|
|
@ -226,12 +226,12 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.3.2" data-path="../advanced/route_validation.html">
|
||||
<li class="chapter " data-level="1.3.2" data-path="../advanced/different_routers.html">
|
||||
|
||||
<a href="../advanced/route_validation.html">
|
||||
<a href="../advanced/different_routers.html">
|
||||
|
||||
|
||||
Route Validation
|
||||
Different Routers
|
||||
|
||||
</a>
|
||||
|
||||
|
|
@ -297,7 +297,20 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.3" data-path="../ring/parameter_coercion.html">
|
||||
<li class="chapter " data-level="1.4.3" data-path="../ring/data_driven_middleware.html">
|
||||
|
||||
<a href="../ring/data_driven_middleware.html">
|
||||
|
||||
|
||||
Data-driven Middleware
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.4" data-path="../ring/parameter_coercion.html">
|
||||
|
||||
<a href="../ring/parameter_coercion.html">
|
||||
|
||||
|
|
@ -310,7 +323,7 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.4" data-path="../ring/compiling_middleware.html">
|
||||
<li class="chapter " data-level="1.4.5" data-path="../ring/compiling_middleware.html">
|
||||
|
||||
<a href="../ring/compiling_middleware.html">
|
||||
|
||||
|
|
@ -400,7 +413,10 @@
|
|||
<section class="normal markdown-section">
|
||||
|
||||
<h1 id="route-syntax">Route Syntax</h1>
|
||||
<p>Raw routes are defined as vectors, which have a String path, optional (non-sequential) route argument and optional child routes. Routes can be wrapped in vectors and lists and <code>nil</code> routes are ignored. Paths can have path-parameters (<code>:id</code>) or catch-all-parameters (<code>*path</code>).</p>
|
||||
<p>Routes are defined as vectors of String path and optional (non-sequential) route argument child routes.</p>
|
||||
<p>Routes can be wrapped in vectors and lists and <code>nil</code> routes are ignored.</p>
|
||||
<p>Paths can have path-parameters (<code>:id</code>) or catch-all-parameters (<code>*path</code>).</p>
|
||||
<h3 id="examples">Examples</h3>
|
||||
<p>Simple route:</p>
|
||||
<pre><code class="lang-clj">[<span class="hljs-string">"/ping"</span>]
|
||||
</code></pre>
|
||||
|
|
@ -431,7 +447,8 @@
|
|||
[<span class="hljs-string">"/api/admin/db"</span> {<span class="hljs-symbol">:middleware</span> [<span class="hljs-symbol">::admin</span>], <span class="hljs-symbol">:name</span> <span class="hljs-symbol">::db</span>}]
|
||||
[<span class="hljs-string">"/api/ping"</span> {<span class="hljs-symbol">:name</span> <span class="hljs-symbol">::ping</span>}]]
|
||||
</code></pre>
|
||||
<p>As routes are just data, it's easy to create them programamtically:</p>
|
||||
<h3 id="generating-routes">Generating routes</h3>
|
||||
<p>As routes are just data, it's easy to create them programmatically:</p>
|
||||
<pre><code class="lang-clj">(<span class="hljs-name"><span class="hljs-builtin-name">defn</span></span> cqrs-routes [actions dev-mode?]
|
||||
[<span class="hljs-string">"/api"</span> {<span class="hljs-symbol">:interceptors</span> [<span class="hljs-symbol">::api</span> <span class="hljs-symbol">::db</span>]}
|
||||
(<span class="hljs-name"><span class="hljs-builtin-name">for</span></span> [[type interceptor] actions
|
||||
|
|
@ -496,7 +513,7 @@
|
|||
<script>
|
||||
var gitbook = gitbook || [];
|
||||
gitbook.push(function() {
|
||||
gitbook.page.hasChanged({"page":{"title":"Route syntax","level":"1.2.1","depth":2,"next":{"title":"Router","level":"1.2.2","depth":2,"path":"basics/router.md","ref":"basics/router.md","articles":[]},"previous":{"title":"Basics","level":"1.2","depth":1,"path":"basics/README.md","ref":"basics/README.md","articles":[{"title":"Route syntax","level":"1.2.1","depth":2,"path":"basics/route_syntax.md","ref":"basics/route_syntax.md","articles":[]},{"title":"Router","level":"1.2.2","depth":2,"path":"basics/router.md","ref":"basics/router.md","articles":[]},{"title":"Path-based Routing","level":"1.2.3","depth":2,"path":"basics/path_based_routing.md","ref":"basics/path_based_routing.md","articles":[]},{"title":"Name-based Routing","level":"1.2.4","depth":2,"path":"basics/name_based_routing.md","ref":"basics/name_based_routing.md","articles":[]},{"title":"Route data","level":"1.2.5","depth":2,"path":"basics/route_data.md","ref":"basics/route_data.md","articles":[]},{"title":"Different Routers","level":"1.2.6","depth":2,"path":"basics/different_routers.md","ref":"basics/different_routers.md","articles":[]}]},"dir":"ltr"},"config":{"plugins":["editlink","github","highlight"],"root":"doc","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"editlink":{"label":"Edit This Page","multilingual":false,"base":"https://github.com/metosin/reitit/tree/master/doc"},"github":{"url":"https://github.com/metosin/reitit"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"gitbook":"*"},"file":{"path":"basics/route_syntax.md","mtime":"2017-10-29T07:29:44.989Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2017-10-29T07:30:20.667Z"},"basePath":"..","book":{"language":""}});
|
||||
gitbook.page.hasChanged({"page":{"title":"Route syntax","level":"1.2.1","depth":2,"next":{"title":"Router","level":"1.2.2","depth":2,"path":"basics/router.md","ref":"basics/router.md","articles":[]},"previous":{"title":"Basics","level":"1.2","depth":1,"path":"basics/README.md","ref":"basics/README.md","articles":[{"title":"Route syntax","level":"1.2.1","depth":2,"path":"basics/route_syntax.md","ref":"basics/route_syntax.md","articles":[]},{"title":"Router","level":"1.2.2","depth":2,"path":"basics/router.md","ref":"basics/router.md","articles":[]},{"title":"Path-based Routing","level":"1.2.3","depth":2,"path":"basics/path_based_routing.md","ref":"basics/path_based_routing.md","articles":[]},{"title":"Name-based Routing","level":"1.2.4","depth":2,"path":"basics/name_based_routing.md","ref":"basics/name_based_routing.md","articles":[]},{"title":"Route data","level":"1.2.5","depth":2,"path":"basics/route_data.md","ref":"basics/route_data.md","articles":[]},{"title":"Route conflicts","level":"1.2.6","depth":2,"path":"basics/route_conflicts.md","ref":"basics/route_conflicts.md","articles":[]}]},"dir":"ltr"},"config":{"plugins":["editlink","github","highlight"],"root":"doc","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"editlink":{"label":"Edit This Page","multilingual":false,"base":"https://github.com/metosin/reitit/tree/master/doc"},"github":{"url":"https://github.com/metosin/reitit"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"gitbook":"*"},"file":{"path":"basics/route_syntax.md","mtime":"2017-10-31T08:26:00.331Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2017-10-31T08:26:38.332Z"},"basePath":"..","book":{"language":""}});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -181,12 +181,12 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.2.6" data-path="different_routers.html">
|
||||
<li class="chapter " data-level="1.2.6" data-path="route_conflicts.html">
|
||||
|
||||
<a href="different_routers.html">
|
||||
<a href="route_conflicts.html">
|
||||
|
||||
|
||||
Different Routers
|
||||
Route conflicts
|
||||
|
||||
</a>
|
||||
|
||||
|
|
@ -213,12 +213,12 @@
|
|||
<ul class="articles">
|
||||
|
||||
|
||||
<li class="chapter " data-level="1.3.1" data-path="../advanced/route_conflicts.html">
|
||||
<li class="chapter " data-level="1.3.1" data-path="../advanced/route_validation.html">
|
||||
|
||||
<a href="../advanced/route_conflicts.html">
|
||||
<a href="../advanced/route_validation.html">
|
||||
|
||||
|
||||
Route conflicts
|
||||
Route Validation
|
||||
|
||||
</a>
|
||||
|
||||
|
|
@ -226,12 +226,12 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.3.2" data-path="../advanced/route_validation.html">
|
||||
<li class="chapter " data-level="1.3.2" data-path="../advanced/different_routers.html">
|
||||
|
||||
<a href="../advanced/route_validation.html">
|
||||
<a href="../advanced/different_routers.html">
|
||||
|
||||
|
||||
Route Validation
|
||||
Different Routers
|
||||
|
||||
</a>
|
||||
|
||||
|
|
@ -297,7 +297,20 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.3" data-path="../ring/parameter_coercion.html">
|
||||
<li class="chapter " data-level="1.4.3" data-path="../ring/data_driven_middleware.html">
|
||||
|
||||
<a href="../ring/data_driven_middleware.html">
|
||||
|
||||
|
||||
Data-driven Middleware
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.4" data-path="../ring/parameter_coercion.html">
|
||||
|
||||
<a href="../ring/parameter_coercion.html">
|
||||
|
||||
|
|
@ -310,7 +323,7 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.4" data-path="../ring/compiling_middleware.html">
|
||||
<li class="chapter " data-level="1.4.5" data-path="../ring/compiling_middleware.html">
|
||||
|
||||
<a href="../ring/compiling_middleware.html">
|
||||
|
||||
|
|
@ -400,8 +413,8 @@
|
|||
<section class="normal markdown-section">
|
||||
|
||||
<h1 id="router">Router</h1>
|
||||
<p>Routes are just data and to do actual routing, we need a Router satisfying the <code>reitit.core/Router</code> protocol. Routers are created with <code>reitit.core/router</code> function, taking the raw routes and optionally an options map. Raw routes gets expanded and optionally coerced and compiled.</p>
|
||||
<p><code>Router</code> protocol:</p>
|
||||
<p>Routes are just data and for routing, we need a router instance satisfying the <code>reitit.core/Router</code> protocol. Routers are created with <code>reitit.core/router</code> function, taking the raw routes and optionally an options map.</p>
|
||||
<p>The <code>Router</code> protocol:</p>
|
||||
<pre><code class="lang-clj">(<span class="hljs-name"><span class="hljs-builtin-name">defprotocol</span></span> Router
|
||||
(<span class="hljs-name">router-name</span> [this])
|
||||
(<span class="hljs-name">routes</span> [this])
|
||||
|
|
@ -419,11 +432,24 @@
|
|||
[<span class="hljs-string">"/ping"</span> <span class="hljs-symbol">::ping</span>]
|
||||
[<span class="hljs-string">"/user/:id"</span> <span class="hljs-symbol">::user</span>]]]))
|
||||
</code></pre>
|
||||
<p>Router flattens the raw routes and expands the route arguments using <code>reitit.core/Expand</code> protocol. By default, <code>Keyword</code>s are expanded to <code>:name</code> and functions are expaned to <code>:handler</code>. <code>nil</code> routes are removed. The expanded routes can be retrieved with router:</p>
|
||||
<p>Name of the created router:</p>
|
||||
<pre><code class="lang-clj">(<span class="hljs-name">r/router-name</span> router)
|
||||
<span class="hljs-comment">; :mixed-router</span>
|
||||
</code></pre>
|
||||
<p>The flattened route tree:</p>
|
||||
<pre><code class="lang-clj">(<span class="hljs-name">r/routes</span> router)
|
||||
<span class="hljs-comment">; [["/api/ping" {:name :user/ping}]</span>
|
||||
<span class="hljs-comment">; ["/api/user/:id" {:name :user/user}]]</span>
|
||||
</code></pre>
|
||||
<h3 id="behind-the-scenes">Behind the scenes</h3>
|
||||
<p>When router is created, the following steps are done:</p>
|
||||
<ul>
|
||||
<li>route tree is flattened</li>
|
||||
<li>route arguments are expanded (via <code>reitit.core/Expand</code> protocol) and optionally coerced</li>
|
||||
<li><a href="advanced/route_conflicts.md">route conflicts</a> are resolved</li>
|
||||
<li>actual <a href="../advanced/different_routers.html">router implementation</a> is selected and created</li>
|
||||
<li>optionally route meta-data gets compiled</li>
|
||||
</ul>
|
||||
|
||||
|
||||
</section>
|
||||
|
|
@ -467,7 +493,7 @@
|
|||
<script>
|
||||
var gitbook = gitbook || [];
|
||||
gitbook.push(function() {
|
||||
gitbook.page.hasChanged({"page":{"title":"Router","level":"1.2.2","depth":2,"next":{"title":"Path-based Routing","level":"1.2.3","depth":2,"path":"basics/path_based_routing.md","ref":"basics/path_based_routing.md","articles":[]},"previous":{"title":"Route syntax","level":"1.2.1","depth":2,"path":"basics/route_syntax.md","ref":"basics/route_syntax.md","articles":[]},"dir":"ltr"},"config":{"plugins":["editlink","github","highlight"],"root":"doc","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"editlink":{"label":"Edit This Page","multilingual":false,"base":"https://github.com/metosin/reitit/tree/master/doc"},"github":{"url":"https://github.com/metosin/reitit"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"gitbook":"*"},"file":{"path":"basics/router.md","mtime":"2017-10-29T07:29:44.989Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2017-10-29T07:30:20.667Z"},"basePath":"..","book":{"language":""}});
|
||||
gitbook.page.hasChanged({"page":{"title":"Router","level":"1.2.2","depth":2,"next":{"title":"Path-based Routing","level":"1.2.3","depth":2,"path":"basics/path_based_routing.md","ref":"basics/path_based_routing.md","articles":[]},"previous":{"title":"Route syntax","level":"1.2.1","depth":2,"path":"basics/route_syntax.md","ref":"basics/route_syntax.md","articles":[]},"dir":"ltr"},"config":{"plugins":["editlink","github","highlight"],"root":"doc","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"editlink":{"label":"Edit This Page","multilingual":false,"base":"https://github.com/metosin/reitit/tree/master/doc"},"github":{"url":"https://github.com/metosin/reitit"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"gitbook":"*"},"file":{"path":"basics/router.md","mtime":"2017-10-31T08:26:00.331Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2017-10-31T08:26:38.332Z"},"basePath":"..","book":{"language":""}});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
|
|
|||
39
index.html
39
index.html
|
|
@ -179,12 +179,12 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.2.6" data-path="basics/different_routers.html">
|
||||
<li class="chapter " data-level="1.2.6" data-path="basics/route_conflicts.html">
|
||||
|
||||
<a href="basics/different_routers.html">
|
||||
<a href="basics/route_conflicts.html">
|
||||
|
||||
|
||||
Different Routers
|
||||
Route conflicts
|
||||
|
||||
</a>
|
||||
|
||||
|
|
@ -211,12 +211,12 @@
|
|||
<ul class="articles">
|
||||
|
||||
|
||||
<li class="chapter " data-level="1.3.1" data-path="advanced/route_conflicts.html">
|
||||
<li class="chapter " data-level="1.3.1" data-path="advanced/route_validation.html">
|
||||
|
||||
<a href="advanced/route_conflicts.html">
|
||||
<a href="advanced/route_validation.html">
|
||||
|
||||
|
||||
Route conflicts
|
||||
Route Validation
|
||||
|
||||
</a>
|
||||
|
||||
|
|
@ -224,12 +224,12 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.3.2" data-path="advanced/route_validation.html">
|
||||
<li class="chapter " data-level="1.3.2" data-path="advanced/different_routers.html">
|
||||
|
||||
<a href="advanced/route_validation.html">
|
||||
<a href="advanced/different_routers.html">
|
||||
|
||||
|
||||
Route Validation
|
||||
Different Routers
|
||||
|
||||
</a>
|
||||
|
||||
|
|
@ -295,7 +295,20 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.3" data-path="ring/parameter_coercion.html">
|
||||
<li class="chapter " data-level="1.4.3" data-path="ring/data_driven_middleware.html">
|
||||
|
||||
<a href="ring/data_driven_middleware.html">
|
||||
|
||||
|
||||
Data-driven Middleware
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.4" data-path="ring/parameter_coercion.html">
|
||||
|
||||
<a href="ring/parameter_coercion.html">
|
||||
|
||||
|
|
@ -308,7 +321,7 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.4" data-path="ring/compiling_middleware.html">
|
||||
<li class="chapter " data-level="1.4.5" data-path="ring/compiling_middleware.html">
|
||||
|
||||
<a href="ring/compiling_middleware.html">
|
||||
|
||||
|
|
@ -401,7 +414,7 @@
|
|||
<p><a href="https://github.com/metosin/reitit" target="_blank">Reitit</a> is a small Clojure(Script) library for data-driven routing.</p>
|
||||
<ul>
|
||||
<li>Simple data-driven <a href="basics/route_syntax.html">route syntax</a></li>
|
||||
<li><a href="advanced/route_conflicts.html">Route conflict resolution</a></li>
|
||||
<li><a href="advanced/route_conflicts.md">Route conflict resolution</a></li>
|
||||
<li>First-class <a href="basics/route_data.html">route meta-data</a></li>
|
||||
<li>Bi-directional routing</li>
|
||||
<li><a href="ring/parameter_coercion.html">Pluggable coercion</a> (<a href="https://clojure.org/about/spec" target="_blank">clojure.spec</a>)</li>
|
||||
|
|
@ -546,7 +559,7 @@
|
|||
<script>
|
||||
var gitbook = gitbook || [];
|
||||
gitbook.push(function() {
|
||||
gitbook.page.hasChanged({"page":{"title":"Introduction","level":"1.1","depth":1,"next":{"title":"Basics","level":"1.2","depth":1,"path":"basics/README.md","ref":"basics/README.md","articles":[{"title":"Route syntax","level":"1.2.1","depth":2,"path":"basics/route_syntax.md","ref":"basics/route_syntax.md","articles":[]},{"title":"Router","level":"1.2.2","depth":2,"path":"basics/router.md","ref":"basics/router.md","articles":[]},{"title":"Path-based Routing","level":"1.2.3","depth":2,"path":"basics/path_based_routing.md","ref":"basics/path_based_routing.md","articles":[]},{"title":"Name-based Routing","level":"1.2.4","depth":2,"path":"basics/name_based_routing.md","ref":"basics/name_based_routing.md","articles":[]},{"title":"Route data","level":"1.2.5","depth":2,"path":"basics/route_data.md","ref":"basics/route_data.md","articles":[]},{"title":"Different Routers","level":"1.2.6","depth":2,"path":"basics/different_routers.md","ref":"basics/different_routers.md","articles":[]}]},"dir":"ltr"},"config":{"plugins":["editlink","github","highlight"],"root":"doc","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"editlink":{"label":"Edit This Page","multilingual":false,"base":"https://github.com/metosin/reitit/tree/master/doc"},"github":{"url":"https://github.com/metosin/reitit"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"gitbook":"*"},"file":{"path":"README.md","mtime":"2017-10-29T07:29:44.989Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2017-10-29T07:30:20.667Z"},"basePath":".","book":{"language":""}});
|
||||
gitbook.page.hasChanged({"page":{"title":"Introduction","level":"1.1","depth":1,"next":{"title":"Basics","level":"1.2","depth":1,"path":"basics/README.md","ref":"basics/README.md","articles":[{"title":"Route syntax","level":"1.2.1","depth":2,"path":"basics/route_syntax.md","ref":"basics/route_syntax.md","articles":[]},{"title":"Router","level":"1.2.2","depth":2,"path":"basics/router.md","ref":"basics/router.md","articles":[]},{"title":"Path-based Routing","level":"1.2.3","depth":2,"path":"basics/path_based_routing.md","ref":"basics/path_based_routing.md","articles":[]},{"title":"Name-based Routing","level":"1.2.4","depth":2,"path":"basics/name_based_routing.md","ref":"basics/name_based_routing.md","articles":[]},{"title":"Route data","level":"1.2.5","depth":2,"path":"basics/route_data.md","ref":"basics/route_data.md","articles":[]},{"title":"Route conflicts","level":"1.2.6","depth":2,"path":"basics/route_conflicts.md","ref":"basics/route_conflicts.md","articles":[]}]},"dir":"ltr"},"config":{"plugins":["editlink","github","highlight"],"root":"doc","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"editlink":{"label":"Edit This Page","multilingual":false,"base":"https://github.com/metosin/reitit/tree/master/doc"},"github":{"url":"https://github.com/metosin/reitit"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"gitbook":"*"},"file":{"path":"README.md","mtime":"2017-10-31T08:26:00.327Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2017-10-31T08:26:38.332Z"},"basePath":".","book":{"language":""}});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -179,12 +179,12 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.2.6" data-path="../basics/different_routers.html">
|
||||
<li class="chapter " data-level="1.2.6" data-path="../basics/route_conflicts.html">
|
||||
|
||||
<a href="../basics/different_routers.html">
|
||||
<a href="../basics/route_conflicts.html">
|
||||
|
||||
|
||||
Different Routers
|
||||
Route conflicts
|
||||
|
||||
</a>
|
||||
|
||||
|
|
@ -211,12 +211,12 @@
|
|||
<ul class="articles">
|
||||
|
||||
|
||||
<li class="chapter " data-level="1.3.1" data-path="../advanced/route_conflicts.html">
|
||||
<li class="chapter " data-level="1.3.1" data-path="../advanced/route_validation.html">
|
||||
|
||||
<a href="../advanced/route_conflicts.html">
|
||||
<a href="../advanced/route_validation.html">
|
||||
|
||||
|
||||
Route conflicts
|
||||
Route Validation
|
||||
|
||||
</a>
|
||||
|
||||
|
|
@ -224,12 +224,12 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.3.2" data-path="../advanced/route_validation.html">
|
||||
<li class="chapter " data-level="1.3.2" data-path="../advanced/different_routers.html">
|
||||
|
||||
<a href="../advanced/route_validation.html">
|
||||
<a href="../advanced/different_routers.html">
|
||||
|
||||
|
||||
Route Validation
|
||||
Different Routers
|
||||
|
||||
</a>
|
||||
|
||||
|
|
@ -295,7 +295,20 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.3" data-path="parameter_coercion.html">
|
||||
<li class="chapter " data-level="1.4.3" data-path="data_driven_middleware.html">
|
||||
|
||||
<a href="data_driven_middleware.html">
|
||||
|
||||
|
||||
Data-driven Middleware
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.4" data-path="parameter_coercion.html">
|
||||
|
||||
<a href="parameter_coercion.html">
|
||||
|
||||
|
|
@ -308,7 +321,7 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter active" data-level="1.4.4" data-path="compiling_middleware.html">
|
||||
<li class="chapter active" data-level="1.4.5" data-path="compiling_middleware.html">
|
||||
|
||||
<a href="compiling_middleware.html">
|
||||
|
||||
|
|
@ -398,10 +411,10 @@
|
|||
<section class="normal markdown-section">
|
||||
|
||||
<h1 id="compiling-middleware">Compiling Middleware</h1>
|
||||
<p>The <a href="ring.html#meta-data-based-extensions">meta-data extensions</a> are a easy way to extend the system. Routes meta-data can be transformed into any shape (records, functions etc.) in route compilation, enabling fast access at request-time.</p>
|
||||
<p>Still, we can do better. As we know the exact route that interceptor/middleware is linked to, we can pass the (compiled) route information into the interceptor/middleware at creation-time. It can extract and transform relevant data just for it and pass it into the actual request-handler via a closure - yielding faster runtime processing.</p>
|
||||
<p>To do this we use <a href="ring.html#middleware-records">middleware records</a> <code>:gen</code> hook instead of the normal <code>:wrap</code>. <code>:gen</code> expects a function of <code>route-meta router-opts => wrap</code>. Middleware can also return <code>nil</code>, which effective unmounts the middleware. Why mount a <code>wrap-enforce-roles</code> middleware for a route if there are no roles required for it?</p>
|
||||
<p>To demonstrate the two approaches, below are response coercion middleware written as normal ring middleware function and as middleware record with <code>:gen</code>. These are the actual codes are from <a href="https://github.com/metosin/reitit/blob/master/src/reitit/coercion.cljc" target="_blank"><code>reitit.coercion</code></a>:</p>
|
||||
<p>The <a href="dynamic_extensions.html">dynamic extensions</a> is a easy way to extend the system. To enable fast lookups into route data, we can compile them into any shape (records, functions etc.) we want, enabling fast access at request-time.</p>
|
||||
<p>Still, we can do better. As we know the exact route that middleware/interceptor is linked to, we can pass the (compiled) route information into the middleware/interceptor at creation-time. It can do local reasoning: extract and transform relevant data just for it and pass it into the actual request-handler via a closure - yielding much faster runtime processing. Middleware/interceptor can also decide not to mount itself. Why mount a <code>wrap-enforce-roles</code> middleware for a route if there are no roles required for it?</p>
|
||||
<p>To enable this we use <a href="data_driven_middleware.html">middleware records</a> <code>:gen</code> hook instead of the normal <code>:wrap</code>. <code>:gen</code> expects a function of <code>route-meta router-opts => wrap</code>. Middleware can also return <code>nil</code>, which effective unmounts the middleware.</p>
|
||||
<p>To demonstrate the two approaches, below are response coercion middleware written as normal ring middleware function and as middleware record with <code>:gen</code>. These are the actual codes are from <a href="https://github.com/metosin/reitit/blob/master/src/reitit/ring/coercion.cljc" target="_blank"><code>reitit.ring.coercion</code></a>:</p>
|
||||
<h2 id="naive">Naive</h2>
|
||||
<ul>
|
||||
<li>Extracts the compiled route information on every request.</li>
|
||||
|
|
@ -409,7 +422,7 @@
|
|||
<pre><code class="lang-clj">(<span class="hljs-name"><span class="hljs-builtin-name">defn</span></span> wrap-coerce-response
|
||||
<span class="hljs-string">"Pluggable response coercion middleware.
|
||||
Expects a :coercion of type `reitit.coercion.protocol/Coercion`
|
||||
and :responses from route meta, otherwise does not mount."</span>
|
||||
and :responses from route meta, otherwise will do nothing."</span>
|
||||
[handler]
|
||||
(<span class="hljs-name"><span class="hljs-builtin-name">fn</span></span>
|
||||
([request]
|
||||
|
|
@ -420,20 +433,17 @@
|
|||
coercion (<span class="hljs-name"><span class="hljs-builtin-name">-></span></span> match <span class="hljs-symbol">:meta</span> <span class="hljs-symbol">:coercion</span>)
|
||||
opts (<span class="hljs-name"><span class="hljs-builtin-name">-></span></span> match <span class="hljs-symbol">:meta</span> <span class="hljs-symbol">:opts</span>)]
|
||||
(<span class="hljs-name"><span class="hljs-builtin-name">if</span></span> (<span class="hljs-name"><span class="hljs-builtin-name">and</span></span> coercion responses)
|
||||
(<span class="hljs-name"><span class="hljs-builtin-name">let</span></span> [coercers (<span class="hljs-name">response-coercers</span> coercion responses opts)
|
||||
coerced (<span class="hljs-name">coerce-response</span> coercers request response)]
|
||||
(<span class="hljs-name">coerce-response</span> coercers request (<span class="hljs-name">handler</span> request)))
|
||||
(<span class="hljs-name">handler</span> request))))
|
||||
(<span class="hljs-name"><span class="hljs-builtin-name">let</span></span> [coercers (<span class="hljs-name">response-coercers</span> coercion responses opts)]
|
||||
(<span class="hljs-name">coerce-response</span> coercers request response))
|
||||
response)))
|
||||
([request respond raise]
|
||||
(<span class="hljs-name"><span class="hljs-builtin-name">let</span></span> [response (<span class="hljs-name">handler</span> request)
|
||||
method (<span class="hljs-symbol">:request-method</span> request)
|
||||
(<span class="hljs-name"><span class="hljs-builtin-name">let</span></span> [method (<span class="hljs-symbol">:request-method</span> request)
|
||||
match (<span class="hljs-name">ring/get-match</span> request)
|
||||
responses (<span class="hljs-name"><span class="hljs-builtin-name">-></span></span> match <span class="hljs-symbol">:result</span> method <span class="hljs-symbol">:meta</span> <span class="hljs-symbol">:responses</span>)
|
||||
coercion (<span class="hljs-name"><span class="hljs-builtin-name">-></span></span> match <span class="hljs-symbol">:meta</span> <span class="hljs-symbol">:coercion</span>)
|
||||
opts (<span class="hljs-name"><span class="hljs-builtin-name">-></span></span> match <span class="hljs-symbol">:meta</span> <span class="hljs-symbol">:opts</span>)]
|
||||
(<span class="hljs-name"><span class="hljs-builtin-name">if</span></span> (<span class="hljs-name"><span class="hljs-builtin-name">and</span></span> coercion responses)
|
||||
(<span class="hljs-name"><span class="hljs-builtin-name">let</span></span> [coercers (<span class="hljs-name">response-coercers</span> coercion responses opts)
|
||||
coerced (<span class="hljs-name">coerce-response</span> coercers request response)]
|
||||
(<span class="hljs-name"><span class="hljs-builtin-name">let</span></span> [coercers (<span class="hljs-name">response-coercers</span> coercion responses opts)]
|
||||
(<span class="hljs-name">handler</span> request #(<span class="hljs-name">respond</span> (<span class="hljs-name">coerce-response</span> coercers request %))))
|
||||
(<span class="hljs-name">handler</span> request respond raise))))))
|
||||
</code></pre>
|
||||
|
|
@ -459,7 +469,7 @@
|
|||
([request respond raise]
|
||||
(<span class="hljs-name">handler</span> request #(<span class="hljs-name">respond</span> (<span class="hljs-name">coerce-response</span> coercers request %)) raise)))))))}))
|
||||
</code></pre>
|
||||
<p>The <code>:gen</code> -version has 50% less code, is easier to reason about and is 2-4x faster on basic perf tests.</p>
|
||||
<p>The <code>:gen</code> -version has 50% less code, is easier to reason about and is twice as faster on basic perf tests.</p>
|
||||
|
||||
|
||||
</section>
|
||||
|
|
@ -499,7 +509,7 @@
|
|||
<script>
|
||||
var gitbook = gitbook || [];
|
||||
gitbook.push(function() {
|
||||
gitbook.page.hasChanged({"page":{"title":"Compiling middleware","level":"1.4.4","depth":2,"next":{"title":"TODO: Swagger & OpenAPI","level":"1.5","depth":1,"ref":"","articles":[]},"previous":{"title":"Parameter coercion","level":"1.4.3","depth":2,"path":"ring/parameter_coercion.md","ref":"ring/parameter_coercion.md","articles":[]},"dir":"ltr"},"config":{"plugins":["editlink","github","highlight"],"root":"doc","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"editlink":{"label":"Edit This Page","multilingual":false,"base":"https://github.com/metosin/reitit/tree/master/doc"},"github":{"url":"https://github.com/metosin/reitit"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"gitbook":"*"},"file":{"path":"ring/compiling_middleware.md","mtime":"2017-10-29T07:29:44.989Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2017-10-29T07:30:20.667Z"},"basePath":"..","book":{"language":""}});
|
||||
gitbook.page.hasChanged({"page":{"title":"Compiling middleware","level":"1.4.5","depth":2,"next":{"title":"TODO: Swagger & OpenAPI","level":"1.5","depth":1,"ref":"","articles":[]},"previous":{"title":"Parameter coercion","level":"1.4.4","depth":2,"path":"ring/parameter_coercion.md","ref":"ring/parameter_coercion.md","articles":[]},"dir":"ltr"},"config":{"plugins":["editlink","github","highlight"],"root":"doc","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"editlink":{"label":"Edit This Page","multilingual":false,"base":"https://github.com/metosin/reitit/tree/master/doc"},"github":{"url":"https://github.com/metosin/reitit"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"gitbook":"*"},"file":{"path":"ring/compiling_middleware.md","mtime":"2017-10-31T08:26:00.331Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2017-10-31T08:26:38.332Z"},"basePath":"..","book":{"language":""}});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
|
|
|||
546
ring/data_driven_middleware.html
Normal file
546
ring/data_driven_middleware.html
Normal file
|
|
@ -0,0 +1,546 @@
|
|||
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="" >
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
||||
<title>Data-driven Middleware · GitBook</title>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="description" content="">
|
||||
<meta name="generator" content="GitBook 3.2.3">
|
||||
|
||||
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../gitbook/style.css">
|
||||
|
||||
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
|
||||
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
|
||||
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<meta name="HandheldFriendly" content="true"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black">
|
||||
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
|
||||
<link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
|
||||
|
||||
|
||||
<link rel="next" href="parameter_coercion.html" />
|
||||
|
||||
|
||||
<link rel="prev" href="dynamic_extensions.html" />
|
||||
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="book">
|
||||
<div class="book-summary">
|
||||
|
||||
|
||||
<div id="book-search-input" role="search">
|
||||
<input type="text" placeholder="Type to search" />
|
||||
</div>
|
||||
|
||||
|
||||
<nav role="navigation">
|
||||
|
||||
|
||||
|
||||
<ul class="summary">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="chapter " data-level="1.1" data-path="../">
|
||||
|
||||
<a href="../">
|
||||
|
||||
|
||||
Introduction
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.2" data-path="../basics/">
|
||||
|
||||
<a href="../basics/">
|
||||
|
||||
|
||||
Basics
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
<ul class="articles">
|
||||
|
||||
|
||||
<li class="chapter " data-level="1.2.1" data-path="../basics/route_syntax.html">
|
||||
|
||||
<a href="../basics/route_syntax.html">
|
||||
|
||||
|
||||
Route syntax
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.2.2" data-path="../basics/router.html">
|
||||
|
||||
<a href="../basics/router.html">
|
||||
|
||||
|
||||
Router
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.2.3" data-path="../basics/path_based_routing.html">
|
||||
|
||||
<a href="../basics/path_based_routing.html">
|
||||
|
||||
|
||||
Path-based Routing
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.2.4" data-path="../basics/name_based_routing.html">
|
||||
|
||||
<a href="../basics/name_based_routing.html">
|
||||
|
||||
|
||||
Name-based Routing
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.2.5" data-path="../basics/route_data.html">
|
||||
|
||||
<a href="../basics/route_data.html">
|
||||
|
||||
|
||||
Route data
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.2.6" data-path="../basics/route_conflicts.html">
|
||||
|
||||
<a href="../basics/route_conflicts.html">
|
||||
|
||||
|
||||
Route conflicts
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.3" data-path="../advanced/">
|
||||
|
||||
<a href="../advanced/">
|
||||
|
||||
|
||||
Advanced
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
<ul class="articles">
|
||||
|
||||
|
||||
<li class="chapter " data-level="1.3.1" data-path="../advanced/route_validation.html">
|
||||
|
||||
<a href="../advanced/route_validation.html">
|
||||
|
||||
|
||||
Route Validation
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.3.2" data-path="../advanced/different_routers.html">
|
||||
|
||||
<a href="../advanced/different_routers.html">
|
||||
|
||||
|
||||
Different Routers
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.3.3" data-path="../advanced/configuring_routers.html">
|
||||
|
||||
<a href="../advanced/configuring_routers.html">
|
||||
|
||||
|
||||
Configuring routers
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4" data-path="./">
|
||||
|
||||
<a href="./">
|
||||
|
||||
|
||||
Ring
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
<ul class="articles">
|
||||
|
||||
|
||||
<li class="chapter " data-level="1.4.1" data-path="ring.html">
|
||||
|
||||
<a href="ring.html">
|
||||
|
||||
|
||||
Ring-router
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.2" data-path="dynamic_extensions.html">
|
||||
|
||||
<a href="dynamic_extensions.html">
|
||||
|
||||
|
||||
Dynamic extensions
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter active" data-level="1.4.3" data-path="data_driven_middleware.html">
|
||||
|
||||
<a href="data_driven_middleware.html">
|
||||
|
||||
|
||||
Data-driven Middleware
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.4" data-path="parameter_coercion.html">
|
||||
|
||||
<a href="parameter_coercion.html">
|
||||
|
||||
|
||||
Parameter coercion
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.5" data-path="compiling_middleware.html">
|
||||
|
||||
<a href="compiling_middleware.html">
|
||||
|
||||
|
||||
Compiling middleware
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.5" >
|
||||
|
||||
<span>
|
||||
|
||||
|
||||
TODO: Swagger & OpenAPI
|
||||
|
||||
</span>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.6" >
|
||||
|
||||
<span>
|
||||
|
||||
|
||||
TODO: Interceptors
|
||||
|
||||
</span>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="divider"></li>
|
||||
|
||||
<li>
|
||||
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">
|
||||
Published with GitBook
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
||||
</nav>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div class="book-body">
|
||||
|
||||
<div class="body-inner">
|
||||
|
||||
|
||||
|
||||
<div class="book-header" role="navigation">
|
||||
|
||||
|
||||
<!-- Title -->
|
||||
<h1>
|
||||
<i class="fa fa-circle-o-notch fa-spin"></i>
|
||||
<a href=".." >Data-driven Middleware</a>
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="page-wrapper" tabindex="-1" role="main">
|
||||
<div class="page-inner">
|
||||
|
||||
<div id="book-search-results">
|
||||
<div class="search-noresults">
|
||||
|
||||
<section class="normal markdown-section">
|
||||
|
||||
<h1 id="data-driven-middleware">Data-driven Middleware</h1>
|
||||
<p>Reitit supports first-class data-driven middleware via <code>reitit.ring.middleware/Middleware</code> records, created with <code>reitit.ring.middleware/create</code> function. The following keys have special purpose:</p>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>key</th>
|
||||
<th>description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><code>:name</code></td>
|
||||
<td>Name of the middleware as qualified keyword (optional,recommended for libs)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>:wrap</code></td>
|
||||
<td>The actual middleware function of <code>handler args? => request => response</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>:gen</code></td>
|
||||
<td>Middleware compile function, see <a href="compiling_middleware.html">compiling middleware</a>.</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>When routes are compiled, all middleware are expanded (and optionally compiled) into <code>Middleware</code> Records and stored in compilation results for later use (api-docs etc). For actual request processing, they are unwrapped into normal middleware functions and composed together producing zero runtime performance penalty. Middleware expansion is backed by <code>reitit.middleware/IntoMiddleware</code> protocol, enabling plain clojure(script) maps to be used.</p>
|
||||
<p>A Record:</p>
|
||||
<pre><code class="lang-clj">(<span class="hljs-name">require</span> '[reitit.middleware <span class="hljs-symbol">:as</span> middleware])
|
||||
|
||||
(<span class="hljs-name"><span class="hljs-builtin-name">def</span></span> wrap2
|
||||
(<span class="hljs-name">middleware/create</span>
|
||||
{<span class="hljs-symbol">:name</span> <span class="hljs-symbol">::wrap2</span>
|
||||
<span class="hljs-symbol">:description</span> <span class="hljs-string">"a nice little mw, takes 1 arg."</span>
|
||||
<span class="hljs-symbol">:wrap</span> wrap}))
|
||||
</code></pre>
|
||||
<p>As plain map:</p>
|
||||
<pre><code class="lang-clj"><span class="hljs-comment">;; plain map</span>
|
||||
(<span class="hljs-name"><span class="hljs-builtin-name">def</span></span> wrap3
|
||||
{<span class="hljs-symbol">:name</span> <span class="hljs-symbol">::wrap3</span>
|
||||
<span class="hljs-symbol">:description</span> <span class="hljs-string">"a nice little mw, :api as arg"</span>
|
||||
<span class="hljs-symbol">:wrap</span> (<span class="hljs-name"><span class="hljs-builtin-name">fn</span></span> [handler]
|
||||
(<span class="hljs-name">wrap</span> handler <span class="hljs-symbol">:api</span>))})
|
||||
</code></pre>
|
||||
<h3 id="todo">TODO</h3>
|
||||
<p>more!</p>
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
</div>
|
||||
<div class="search-results">
|
||||
<div class="has-results">
|
||||
|
||||
<h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
|
||||
<ul class="search-results-list"></ul>
|
||||
|
||||
</div>
|
||||
<div class="no-results">
|
||||
|
||||
<h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<a href="dynamic_extensions.html" class="navigation navigation-prev " aria-label="Previous page: Dynamic extensions">
|
||||
<i class="fa fa-angle-left"></i>
|
||||
</a>
|
||||
|
||||
|
||||
<a href="parameter_coercion.html" class="navigation navigation-next " aria-label="Next page: Parameter coercion">
|
||||
<i class="fa fa-angle-right"></i>
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var gitbook = gitbook || [];
|
||||
gitbook.push(function() {
|
||||
gitbook.page.hasChanged({"page":{"title":"Data-driven Middleware","level":"1.4.3","depth":2,"next":{"title":"Parameter coercion","level":"1.4.4","depth":2,"path":"ring/parameter_coercion.md","ref":"ring/parameter_coercion.md","articles":[]},"previous":{"title":"Dynamic extensions","level":"1.4.2","depth":2,"path":"ring/dynamic_extensions.md","ref":"ring/dynamic_extensions.md","articles":[]},"dir":"ltr"},"config":{"plugins":["editlink","github","highlight"],"root":"doc","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"editlink":{"label":"Edit This Page","multilingual":false,"base":"https://github.com/metosin/reitit/tree/master/doc"},"github":{"url":"https://github.com/metosin/reitit"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"gitbook":"*"},"file":{"path":"ring/data_driven_middleware.md","mtime":"2017-10-31T08:26:00.331Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2017-10-31T08:26:38.332Z"},"basePath":"..","book":{"language":""}});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook.js"></script>
|
||||
<script src="../gitbook/theme.js"></script>
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook-plugin-editlink/plugin.js"></script>
|
||||
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook-plugin-github/plugin.js"></script>
|
||||
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
|
||||
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook-plugin-search/search.js"></script>
|
||||
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
|
||||
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
|
||||
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
|
||||
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
|
@ -57,7 +57,7 @@
|
|||
<link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
|
||||
|
||||
|
||||
<link rel="next" href="parameter_coercion.html" />
|
||||
<link rel="next" href="data_driven_middleware.html" />
|
||||
|
||||
|
||||
<link rel="prev" href="ring.html" />
|
||||
|
|
@ -181,12 +181,12 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.2.6" data-path="../basics/different_routers.html">
|
||||
<li class="chapter " data-level="1.2.6" data-path="../basics/route_conflicts.html">
|
||||
|
||||
<a href="../basics/different_routers.html">
|
||||
<a href="../basics/route_conflicts.html">
|
||||
|
||||
|
||||
Different Routers
|
||||
Route conflicts
|
||||
|
||||
</a>
|
||||
|
||||
|
|
@ -213,12 +213,12 @@
|
|||
<ul class="articles">
|
||||
|
||||
|
||||
<li class="chapter " data-level="1.3.1" data-path="../advanced/route_conflicts.html">
|
||||
<li class="chapter " data-level="1.3.1" data-path="../advanced/route_validation.html">
|
||||
|
||||
<a href="../advanced/route_conflicts.html">
|
||||
<a href="../advanced/route_validation.html">
|
||||
|
||||
|
||||
Route conflicts
|
||||
Route Validation
|
||||
|
||||
</a>
|
||||
|
||||
|
|
@ -226,12 +226,12 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.3.2" data-path="../advanced/route_validation.html">
|
||||
<li class="chapter " data-level="1.3.2" data-path="../advanced/different_routers.html">
|
||||
|
||||
<a href="../advanced/route_validation.html">
|
||||
<a href="../advanced/different_routers.html">
|
||||
|
||||
|
||||
Route Validation
|
||||
Different Routers
|
||||
|
||||
</a>
|
||||
|
||||
|
|
@ -297,7 +297,20 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.3" data-path="parameter_coercion.html">
|
||||
<li class="chapter " data-level="1.4.3" data-path="data_driven_middleware.html">
|
||||
|
||||
<a href="data_driven_middleware.html">
|
||||
|
||||
|
||||
Data-driven Middleware
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.4" data-path="parameter_coercion.html">
|
||||
|
||||
<a href="parameter_coercion.html">
|
||||
|
||||
|
|
@ -310,7 +323,7 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.4" data-path="compiling_middleware.html">
|
||||
<li class="chapter " data-level="1.4.5" data-path="compiling_middleware.html">
|
||||
|
||||
<a href="compiling_middleware.html">
|
||||
|
||||
|
|
@ -400,14 +413,14 @@
|
|||
<section class="normal markdown-section">
|
||||
|
||||
<h1 id="dynamic-extensions">Dynamic extensions</h1>
|
||||
<p><code>ring-handler</code> injects the <code>Match</code> into a request and it can be extracted at runtime with <code>reitit.ring/get-match</code>. This can be used to build dynamic extensions to the system.</p>
|
||||
<p><code>ring-handler</code> injects the <code>Match</code> into a request and it can be extracted at runtime with <code>reitit.ring/get-match</code>. This can be used to build ad-hoc extensions to the system.</p>
|
||||
<p>Example middleware to guard routes based on user roles:</p>
|
||||
<pre><code class="lang-clj">(<span class="hljs-name">require</span> '[clojure.set <span class="hljs-symbol">:as</span> set])
|
||||
|
||||
(<span class="hljs-name"><span class="hljs-builtin-name">defn</span></span> wrap-enforce-roles [handler]
|
||||
(<span class="hljs-name"><span class="hljs-builtin-name">fn</span></span> [{<span class="hljs-symbol">:keys</span> [<span class="hljs-symbol">::roles</span>] <span class="hljs-symbol">:as</span> request}]
|
||||
(<span class="hljs-name"><span class="hljs-builtin-name">let</span></span> [required (<span class="hljs-name">some-></span> request (<span class="hljs-name">ring/get-match</span>) <span class="hljs-symbol">:meta</span> <span class="hljs-symbol">::roles</span>)]
|
||||
(<span class="hljs-name"><span class="hljs-builtin-name">if</span></span> (<span class="hljs-name"><span class="hljs-builtin-name">and</span></span> (<span class="hljs-name"><span class="hljs-builtin-name">seq</span></span> required) (<span class="hljs-name"><span class="hljs-builtin-name">not</span></span> (<span class="hljs-name">set/intersection</span> required roles)))
|
||||
(<span class="hljs-name"><span class="hljs-builtin-name">if</span></span> (<span class="hljs-name"><span class="hljs-builtin-name">and</span></span> (<span class="hljs-name"><span class="hljs-builtin-name">seq</span></span> required) (<span class="hljs-name"><span class="hljs-builtin-name">not</span></span> (<span class="hljs-name">set/subset?</span> required roles)))
|
||||
{<span class="hljs-symbol">:status</span> <span class="hljs-number">403</span>, <span class="hljs-symbol">:body</span> <span class="hljs-string">"forbidden"</span>}
|
||||
(<span class="hljs-name">handler</span> request)))))
|
||||
</code></pre>
|
||||
|
|
@ -467,7 +480,7 @@
|
|||
</a>
|
||||
|
||||
|
||||
<a href="parameter_coercion.html" class="navigation navigation-next " aria-label="Next page: Parameter coercion">
|
||||
<a href="data_driven_middleware.html" class="navigation navigation-next " aria-label="Next page: Data-driven Middleware">
|
||||
<i class="fa fa-angle-right"></i>
|
||||
</a>
|
||||
|
||||
|
|
@ -478,7 +491,7 @@
|
|||
<script>
|
||||
var gitbook = gitbook || [];
|
||||
gitbook.push(function() {
|
||||
gitbook.page.hasChanged({"page":{"title":"Dynamic extensions","level":"1.4.2","depth":2,"next":{"title":"Parameter coercion","level":"1.4.3","depth":2,"path":"ring/parameter_coercion.md","ref":"ring/parameter_coercion.md","articles":[]},"previous":{"title":"Ring-router","level":"1.4.1","depth":2,"path":"ring/ring.md","ref":"ring/ring.md","articles":[]},"dir":"ltr"},"config":{"plugins":["editlink","github","highlight"],"root":"doc","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"editlink":{"label":"Edit This Page","multilingual":false,"base":"https://github.com/metosin/reitit/tree/master/doc"},"github":{"url":"https://github.com/metosin/reitit"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"gitbook":"*"},"file":{"path":"ring/dynamic_extensions.md","mtime":"2017-10-29T07:29:44.989Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2017-10-29T07:30:20.667Z"},"basePath":"..","book":{"language":""}});
|
||||
gitbook.page.hasChanged({"page":{"title":"Dynamic extensions","level":"1.4.2","depth":2,"next":{"title":"Data-driven Middleware","level":"1.4.3","depth":2,"path":"ring/data_driven_middleware.md","ref":"ring/data_driven_middleware.md","articles":[]},"previous":{"title":"Ring-router","level":"1.4.1","depth":2,"path":"ring/ring.md","ref":"ring/ring.md","articles":[]},"dir":"ltr"},"config":{"plugins":["editlink","github","highlight"],"root":"doc","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"editlink":{"label":"Edit This Page","multilingual":false,"base":"https://github.com/metosin/reitit/tree/master/doc"},"github":{"url":"https://github.com/metosin/reitit"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"gitbook":"*"},"file":{"path":"ring/dynamic_extensions.md","mtime":"2017-10-31T08:26:00.331Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2017-10-31T08:26:38.332Z"},"basePath":"..","book":{"language":""}});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -181,12 +181,12 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.2.6" data-path="../basics/different_routers.html">
|
||||
<li class="chapter " data-level="1.2.6" data-path="../basics/route_conflicts.html">
|
||||
|
||||
<a href="../basics/different_routers.html">
|
||||
<a href="../basics/route_conflicts.html">
|
||||
|
||||
|
||||
Different Routers
|
||||
Route conflicts
|
||||
|
||||
</a>
|
||||
|
||||
|
|
@ -213,12 +213,12 @@
|
|||
<ul class="articles">
|
||||
|
||||
|
||||
<li class="chapter " data-level="1.3.1" data-path="../advanced/route_conflicts.html">
|
||||
<li class="chapter " data-level="1.3.1" data-path="../advanced/route_validation.html">
|
||||
|
||||
<a href="../advanced/route_conflicts.html">
|
||||
<a href="../advanced/route_validation.html">
|
||||
|
||||
|
||||
Route conflicts
|
||||
Route Validation
|
||||
|
||||
</a>
|
||||
|
||||
|
|
@ -226,12 +226,12 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.3.2" data-path="../advanced/route_validation.html">
|
||||
<li class="chapter " data-level="1.3.2" data-path="../advanced/different_routers.html">
|
||||
|
||||
<a href="../advanced/route_validation.html">
|
||||
<a href="../advanced/different_routers.html">
|
||||
|
||||
|
||||
Route Validation
|
||||
Different Routers
|
||||
|
||||
</a>
|
||||
|
||||
|
|
@ -297,7 +297,20 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.3" data-path="parameter_coercion.html">
|
||||
<li class="chapter " data-level="1.4.3" data-path="data_driven_middleware.html">
|
||||
|
||||
<a href="data_driven_middleware.html">
|
||||
|
||||
|
||||
Data-driven Middleware
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.4" data-path="parameter_coercion.html">
|
||||
|
||||
<a href="parameter_coercion.html">
|
||||
|
||||
|
|
@ -310,7 +323,7 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.4" data-path="compiling_middleware.html">
|
||||
<li class="chapter " data-level="1.4.5" data-path="compiling_middleware.html">
|
||||
|
||||
<a href="compiling_middleware.html">
|
||||
|
||||
|
|
@ -403,6 +416,7 @@
|
|||
<ul>
|
||||
<li><a href="ring.html">Ring-router</a></li>
|
||||
<li><a href="dynamic_extensions.html">Dynamic extensions</a></li>
|
||||
<li><a href="data_driven_middleware.html">Data-driven Middleware</a></li>
|
||||
<li><a href="parameter_coercion.html">Parameter coercion</a></li>
|
||||
<li><a href="compiling_middleware.html">Compiling middleware</a></li>
|
||||
</ul>
|
||||
|
|
@ -449,7 +463,7 @@
|
|||
<script>
|
||||
var gitbook = gitbook || [];
|
||||
gitbook.push(function() {
|
||||
gitbook.page.hasChanged({"page":{"title":"Ring","level":"1.4","depth":1,"next":{"title":"Ring-router","level":"1.4.1","depth":2,"path":"ring/ring.md","ref":"ring/ring.md","articles":[]},"previous":{"title":"Configuring routers","level":"1.3.3","depth":2,"path":"advanced/configuring_routers.md","ref":"advanced/configuring_routers.md","articles":[]},"dir":"ltr"},"config":{"plugins":["editlink","github","highlight"],"root":"doc","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"editlink":{"label":"Edit This Page","multilingual":false,"base":"https://github.com/metosin/reitit/tree/master/doc"},"github":{"url":"https://github.com/metosin/reitit"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"gitbook":"*"},"file":{"path":"ring/README.md","mtime":"2017-10-29T07:29:44.989Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2017-10-29T07:30:20.667Z"},"basePath":"..","book":{"language":""}});
|
||||
gitbook.page.hasChanged({"page":{"title":"Ring","level":"1.4","depth":1,"next":{"title":"Ring-router","level":"1.4.1","depth":2,"path":"ring/ring.md","ref":"ring/ring.md","articles":[]},"previous":{"title":"Configuring routers","level":"1.3.3","depth":2,"path":"advanced/configuring_routers.md","ref":"advanced/configuring_routers.md","articles":[]},"dir":"ltr"},"config":{"plugins":["editlink","github","highlight"],"root":"doc","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"editlink":{"label":"Edit This Page","multilingual":false,"base":"https://github.com/metosin/reitit/tree/master/doc"},"github":{"url":"https://github.com/metosin/reitit"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"gitbook":"*"},"file":{"path":"ring/README.md","mtime":"2017-10-31T08:26:00.331Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2017-10-31T08:26:38.332Z"},"basePath":"..","book":{"language":""}});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@
|
|||
<link rel="next" href="compiling_middleware.html" />
|
||||
|
||||
|
||||
<link rel="prev" href="dynamic_extensions.html" />
|
||||
<link rel="prev" href="data_driven_middleware.html" />
|
||||
|
||||
|
||||
</head>
|
||||
|
|
@ -181,12 +181,12 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.2.6" data-path="../basics/different_routers.html">
|
||||
<li class="chapter " data-level="1.2.6" data-path="../basics/route_conflicts.html">
|
||||
|
||||
<a href="../basics/different_routers.html">
|
||||
<a href="../basics/route_conflicts.html">
|
||||
|
||||
|
||||
Different Routers
|
||||
Route conflicts
|
||||
|
||||
</a>
|
||||
|
||||
|
|
@ -213,12 +213,12 @@
|
|||
<ul class="articles">
|
||||
|
||||
|
||||
<li class="chapter " data-level="1.3.1" data-path="../advanced/route_conflicts.html">
|
||||
<li class="chapter " data-level="1.3.1" data-path="../advanced/route_validation.html">
|
||||
|
||||
<a href="../advanced/route_conflicts.html">
|
||||
<a href="../advanced/route_validation.html">
|
||||
|
||||
|
||||
Route conflicts
|
||||
Route Validation
|
||||
|
||||
</a>
|
||||
|
||||
|
|
@ -226,12 +226,12 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.3.2" data-path="../advanced/route_validation.html">
|
||||
<li class="chapter " data-level="1.3.2" data-path="../advanced/different_routers.html">
|
||||
|
||||
<a href="../advanced/route_validation.html">
|
||||
<a href="../advanced/different_routers.html">
|
||||
|
||||
|
||||
Route Validation
|
||||
Different Routers
|
||||
|
||||
</a>
|
||||
|
||||
|
|
@ -297,7 +297,20 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter active" data-level="1.4.3" data-path="parameter_coercion.html">
|
||||
<li class="chapter " data-level="1.4.3" data-path="data_driven_middleware.html">
|
||||
|
||||
<a href="data_driven_middleware.html">
|
||||
|
||||
|
||||
Data-driven Middleware
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter active" data-level="1.4.4" data-path="parameter_coercion.html">
|
||||
|
||||
<a href="parameter_coercion.html">
|
||||
|
||||
|
|
@ -310,7 +323,7 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.4" data-path="compiling_middleware.html">
|
||||
<li class="chapter " data-level="1.4.5" data-path="compiling_middleware.html">
|
||||
|
||||
<a href="compiling_middleware.html">
|
||||
|
||||
|
|
@ -400,11 +413,11 @@
|
|||
<section class="normal markdown-section">
|
||||
|
||||
<h1 id="parameter-coercion">Parameter coercion</h1>
|
||||
<p>Reitit provides pluggable parameter coercion via <code>reitit.coercion.protocol/Coercion</code> protocol, originally introduced in <a href="https://clojars.org/metosin/compojure-api" target="_blank">compojure-api</a>. Reitit ships with <code>reitit.coercion.spec/SpecCoercion</code> providing implemenation for <a href="https://clojure.org/about/spec" target="_blank">clojure.spec</a> and <a href="https://github.com/metosin/spec-tools#data-specs" target="_blank">data-specs</a>.</p>
|
||||
<p>Reitit provides pluggable parameter coercion via <code>reitit.ring.coercion.protocol/Coercion</code> protocol, originally introduced in <a href="https://clojars.org/metosin/compojure-api" target="_blank">compojure-api</a>. Reitit ships with <code>reitit.ring.coercion.spec/SpecCoercion</code> providing implemenation for <a href="https://clojure.org/about/spec" target="_blank">clojure.spec</a> and <a href="https://github.com/metosin/spec-tools#data-specs" target="_blank">data-specs</a>.</p>
|
||||
<p><strong>NOTE</strong>: Before Clojure 1.9.0 is shipped, to use the spec-coercion, one needs to add the following dependencies manually to the project:</p>
|
||||
<pre><code class="lang-clj">[org.clojure/clojure <span class="hljs-string">"1.9.0-alpha20"</span>]
|
||||
<pre><code class="lang-clj">[org.clojure/clojure <span class="hljs-string">"1.9.0-beta2"</span>]
|
||||
[org.clojure/spec.alpha <span class="hljs-string">"0.1.123"</span>]
|
||||
[metosin/spec-tools <span class="hljs-string">"0.3.3"</span>]
|
||||
[metosin/spec-tools <span class="hljs-string">"0.4.0"</span>]
|
||||
</code></pre>
|
||||
<h3 id="ring-request-and-response-coercion">Ring request and response coercion</h3>
|
||||
<p>To use <code>Coercion</code> with Ring, one needs to do the following:</p>
|
||||
|
|
@ -415,14 +428,18 @@
|
|||
</ul>
|
||||
</li>
|
||||
<li>Define a <code>Coercion</code> to route meta-data under <code>:coercion</code></li>
|
||||
<li>Mount request & response coercion middleware to the routes.</li>
|
||||
<li>Mount request & response coercion middleware to the routes (recommended to mount to all routes under router as they mounted only to routes which have the parameters / responses defined):<ul>
|
||||
<li><code>reitit.ring.coercion/gen-wrap-coerce-parameters</code></li>
|
||||
<li><code>gen-wrap-coerce-parameters/gen-wrap-coerce-responses</code></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ol>
|
||||
<p>If the request coercion succeeds, the coerced parameters are injected into request under <code>:parameters</code>.</p>
|
||||
<p>If either request or response coercion fails, an descriptive error is thrown.</p>
|
||||
<h4 id="example-with-data-specs">Example with data-specs</h4>
|
||||
<pre><code class="lang-clj">(<span class="hljs-name">require</span> '[reitit.ring <span class="hljs-symbol">:as</span> ring])
|
||||
(<span class="hljs-name">require</span> '[reitit.coercion <span class="hljs-symbol">:as</span> coercion])
|
||||
(<span class="hljs-name">require</span> '[reitit.coercion.spec <span class="hljs-symbol">:as</span> spec])
|
||||
(<span class="hljs-name">require</span> '[reitit.ring.coercion <span class="hljs-symbol">:as</span> coercion])
|
||||
(<span class="hljs-name">require</span> '[reitit.ring.coercion.spec <span class="hljs-symbol">:as</span> spec])
|
||||
|
||||
(<span class="hljs-name"><span class="hljs-builtin-name">def</span></span> app
|
||||
(<span class="hljs-name">ring/ring-handler</span>
|
||||
|
|
@ -444,9 +461,10 @@
|
|||
<span class="hljs-comment">; {:status 200, :body {:total 3}}</span>
|
||||
</code></pre>
|
||||
<h4 id="example-with-specs">Example with specs</h4>
|
||||
<p>Currently, <code>clojure.spec</code> <a href="https://dev.clojure.org/jira/browse/CLJ-2116" target="_blank">doesn't support runtime transformations via conforming</a>, so one needs to wrap all specs with <code>spec-tools.core/spec</code>.</p>
|
||||
<pre><code class="lang-clj">(<span class="hljs-name">require</span> '[reitit.ring <span class="hljs-symbol">:as</span> ring])
|
||||
(<span class="hljs-name">require</span> '[reitit.coercion <span class="hljs-symbol">:as</span> coercion])
|
||||
(<span class="hljs-name">require</span> '[reitit.coercion.spec <span class="hljs-symbol">:as</span> spec])
|
||||
(<span class="hljs-name">require</span> '[reitit.ring.coercion <span class="hljs-symbol">:as</span> coercion])
|
||||
(<span class="hljs-name">require</span> '[reitit.ring.coercion.spec <span class="hljs-symbol">:as</span> spec])
|
||||
(<span class="hljs-name">require</span> '[clojure.spec.alpha <span class="hljs-symbol">:as</span> s])
|
||||
(<span class="hljs-name">require</span> '[spec-tools.core <span class="hljs-symbol">:as</span> st])
|
||||
|
||||
|
|
@ -502,7 +520,7 @@
|
|||
|
||||
|
||||
|
||||
<a href="dynamic_extensions.html" class="navigation navigation-prev " aria-label="Previous page: Dynamic extensions">
|
||||
<a href="data_driven_middleware.html" class="navigation navigation-prev " aria-label="Previous page: Data-driven Middleware">
|
||||
<i class="fa fa-angle-left"></i>
|
||||
</a>
|
||||
|
||||
|
|
@ -518,7 +536,7 @@
|
|||
<script>
|
||||
var gitbook = gitbook || [];
|
||||
gitbook.push(function() {
|
||||
gitbook.page.hasChanged({"page":{"title":"Parameter coercion","level":"1.4.3","depth":2,"next":{"title":"Compiling middleware","level":"1.4.4","depth":2,"path":"ring/compiling_middleware.md","ref":"ring/compiling_middleware.md","articles":[]},"previous":{"title":"Dynamic extensions","level":"1.4.2","depth":2,"path":"ring/dynamic_extensions.md","ref":"ring/dynamic_extensions.md","articles":[]},"dir":"ltr"},"config":{"plugins":["editlink","github","highlight"],"root":"doc","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"editlink":{"label":"Edit This Page","multilingual":false,"base":"https://github.com/metosin/reitit/tree/master/doc"},"github":{"url":"https://github.com/metosin/reitit"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"gitbook":"*"},"file":{"path":"ring/parameter_coercion.md","mtime":"2017-10-29T07:29:44.989Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2017-10-29T07:30:20.667Z"},"basePath":"..","book":{"language":""}});
|
||||
gitbook.page.hasChanged({"page":{"title":"Parameter coercion","level":"1.4.4","depth":2,"next":{"title":"Compiling middleware","level":"1.4.5","depth":2,"path":"ring/compiling_middleware.md","ref":"ring/compiling_middleware.md","articles":[]},"previous":{"title":"Data-driven Middleware","level":"1.4.3","depth":2,"path":"ring/data_driven_middleware.md","ref":"ring/data_driven_middleware.md","articles":[]},"dir":"ltr"},"config":{"plugins":["editlink","github","highlight"],"root":"doc","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"editlink":{"label":"Edit This Page","multilingual":false,"base":"https://github.com/metosin/reitit/tree/master/doc"},"github":{"url":"https://github.com/metosin/reitit"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"gitbook":"*"},"file":{"path":"ring/parameter_coercion.md","mtime":"2017-10-31T08:26:00.331Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2017-10-31T08:26:38.332Z"},"basePath":"..","book":{"language":""}});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -181,12 +181,12 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.2.6" data-path="../basics/different_routers.html">
|
||||
<li class="chapter " data-level="1.2.6" data-path="../basics/route_conflicts.html">
|
||||
|
||||
<a href="../basics/different_routers.html">
|
||||
<a href="../basics/route_conflicts.html">
|
||||
|
||||
|
||||
Different Routers
|
||||
Route conflicts
|
||||
|
||||
</a>
|
||||
|
||||
|
|
@ -213,12 +213,12 @@
|
|||
<ul class="articles">
|
||||
|
||||
|
||||
<li class="chapter " data-level="1.3.1" data-path="../advanced/route_conflicts.html">
|
||||
<li class="chapter " data-level="1.3.1" data-path="../advanced/route_validation.html">
|
||||
|
||||
<a href="../advanced/route_conflicts.html">
|
||||
<a href="../advanced/route_validation.html">
|
||||
|
||||
|
||||
Route conflicts
|
||||
Route Validation
|
||||
|
||||
</a>
|
||||
|
||||
|
|
@ -226,12 +226,12 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.3.2" data-path="../advanced/route_validation.html">
|
||||
<li class="chapter " data-level="1.3.2" data-path="../advanced/different_routers.html">
|
||||
|
||||
<a href="../advanced/route_validation.html">
|
||||
<a href="../advanced/different_routers.html">
|
||||
|
||||
|
||||
Route Validation
|
||||
Different Routers
|
||||
|
||||
</a>
|
||||
|
||||
|
|
@ -297,7 +297,20 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.3" data-path="parameter_coercion.html">
|
||||
<li class="chapter " data-level="1.4.3" data-path="data_driven_middleware.html">
|
||||
|
||||
<a href="data_driven_middleware.html">
|
||||
|
||||
|
||||
Data-driven Middleware
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.4" data-path="parameter_coercion.html">
|
||||
|
||||
<a href="parameter_coercion.html">
|
||||
|
||||
|
|
@ -310,7 +323,7 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.4" data-path="compiling_middleware.html">
|
||||
<li class="chapter " data-level="1.4.5" data-path="compiling_middleware.html">
|
||||
|
||||
<a href="compiling_middleware.html">
|
||||
|
||||
|
|
@ -419,7 +432,7 @@
|
|||
(<span class="hljs-name">app</span> {<span class="hljs-symbol">:request-method</span> <span class="hljs-symbol">:get</span>, <span class="hljs-symbol">:uri</span> <span class="hljs-string">"/ping"</span>})
|
||||
<span class="hljs-comment">; {:status 200, :body "ok"}</span>
|
||||
</code></pre>
|
||||
<p>The expanded routes:</p>
|
||||
<p>The expanded routes shows the compilation results:</p>
|
||||
<pre><code class="lang-clj">(<span class="hljs-name"><span class="hljs-builtin-name">-></span></span> app (<span class="hljs-name">ring/get-router</span>) (<span class="hljs-name">reitit/routes</span>))
|
||||
<span class="hljs-comment">; [["/ping"</span>
|
||||
<span class="hljs-comment">; {:handler #object[...]}</span>
|
||||
|
|
@ -443,7 +456,7 @@
|
|||
(<span class="hljs-name">app</span> {<span class="hljs-symbol">:request-method</span> <span class="hljs-symbol">:put</span>, <span class="hljs-symbol">:uri</span> <span class="hljs-string">"/ping"</span>})
|
||||
<span class="hljs-comment">; nil</span>
|
||||
</code></pre>
|
||||
<p>Reverse routing:</p>
|
||||
<p>Name-based reverse routing:</p>
|
||||
<pre><code class="lang-clj">(<span class="hljs-name"><span class="hljs-builtin-name">-></span></span> app
|
||||
(<span class="hljs-name">ring/get-router</span>)
|
||||
(<span class="hljs-name">reitit/match-by-name</span> <span class="hljs-symbol">::ping</span>)
|
||||
|
|
@ -451,9 +464,9 @@
|
|||
<span class="hljs-comment">; "/ping"</span>
|
||||
</code></pre>
|
||||
<h1 id="middleware">Middleware</h1>
|
||||
<p>Middleware can be added with a <code>:middleware</code> key, with a vector value of the following:</p>
|
||||
<p>Middleware can be added with a <code>:middleware</code> key, either to top-level or under <code>:request-method</code> submap. It's value should be a vector value of the following:</p>
|
||||
<ol>
|
||||
<li>ring middleware function <code>handler -> request -> response</code></li>
|
||||
<li>normal ring middleware function <code>handler -> request -> response</code></li>
|
||||
<li>vector of middleware function <code>handler ?args -> request -> response</code> and optinally it's args.</li>
|
||||
</ol>
|
||||
<p>A middleware and a handler:</p>
|
||||
|
|
@ -472,7 +485,7 @@
|
|||
[<span class="hljs-string">"/ping"</span> handler]
|
||||
[<span class="hljs-string">"/admin"</span> {<span class="hljs-symbol">:middleware</span> [[wrap <span class="hljs-symbol">:admin</span>]]}
|
||||
[<span class="hljs-string">"/db"</span> {<span class="hljs-symbol">:middleware</span> [[wrap <span class="hljs-symbol">:db</span>]]
|
||||
<span class="hljs-symbol">:delete</span> {<span class="hljs-symbol">:middleware</span> [#(<span class="hljs-name">wrap</span> % <span class="hljs-symbol">:delete</span>)]
|
||||
<span class="hljs-symbol">:delete</span> {<span class="hljs-symbol">:middleware</span> [[wrap <span class="hljs-symbol">:delete</span>]]
|
||||
<span class="hljs-symbol">:handler</span> handler}}]]])))
|
||||
</code></pre>
|
||||
<p>Middleware is applied correctly:</p>
|
||||
|
|
@ -527,7 +540,7 @@
|
|||
<script>
|
||||
var gitbook = gitbook || [];
|
||||
gitbook.push(function() {
|
||||
gitbook.page.hasChanged({"page":{"title":"Ring-router","level":"1.4.1","depth":2,"next":{"title":"Dynamic extensions","level":"1.4.2","depth":2,"path":"ring/dynamic_extensions.md","ref":"ring/dynamic_extensions.md","articles":[]},"previous":{"title":"Ring","level":"1.4","depth":1,"path":"ring/README.md","ref":"ring/README.md","articles":[{"title":"Ring-router","level":"1.4.1","depth":2,"path":"ring/ring.md","ref":"ring/ring.md","articles":[]},{"title":"Dynamic extensions","level":"1.4.2","depth":2,"path":"ring/dynamic_extensions.md","ref":"ring/dynamic_extensions.md","articles":[]},{"title":"Parameter coercion","level":"1.4.3","depth":2,"path":"ring/parameter_coercion.md","ref":"ring/parameter_coercion.md","articles":[]},{"title":"Compiling middleware","level":"1.4.4","depth":2,"path":"ring/compiling_middleware.md","ref":"ring/compiling_middleware.md","articles":[]}]},"dir":"ltr"},"config":{"plugins":["editlink","github","highlight"],"root":"doc","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"editlink":{"label":"Edit This Page","multilingual":false,"base":"https://github.com/metosin/reitit/tree/master/doc"},"github":{"url":"https://github.com/metosin/reitit"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"gitbook":"*"},"file":{"path":"ring/ring.md","mtime":"2017-10-29T07:29:44.989Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2017-10-29T07:30:20.667Z"},"basePath":"..","book":{"language":""}});
|
||||
gitbook.page.hasChanged({"page":{"title":"Ring-router","level":"1.4.1","depth":2,"next":{"title":"Dynamic extensions","level":"1.4.2","depth":2,"path":"ring/dynamic_extensions.md","ref":"ring/dynamic_extensions.md","articles":[]},"previous":{"title":"Ring","level":"1.4","depth":1,"path":"ring/README.md","ref":"ring/README.md","articles":[{"title":"Ring-router","level":"1.4.1","depth":2,"path":"ring/ring.md","ref":"ring/ring.md","articles":[]},{"title":"Dynamic extensions","level":"1.4.2","depth":2,"path":"ring/dynamic_extensions.md","ref":"ring/dynamic_extensions.md","articles":[]},{"title":"Data-driven Middleware","level":"1.4.3","depth":2,"path":"ring/data_driven_middleware.md","ref":"ring/data_driven_middleware.md","articles":[]},{"title":"Parameter coercion","level":"1.4.4","depth":2,"path":"ring/parameter_coercion.md","ref":"ring/parameter_coercion.md","articles":[]},{"title":"Compiling middleware","level":"1.4.5","depth":2,"path":"ring/compiling_middleware.md","ref":"ring/compiling_middleware.md","articles":[]}]},"dir":"ltr"},"config":{"plugins":["editlink","github","highlight"],"root":"doc","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"editlink":{"label":"Edit This Page","multilingual":false,"base":"https://github.com/metosin/reitit/tree/master/doc"},"github":{"url":"https://github.com/metosin/reitit"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"gitbook":"*"},"file":{"path":"ring/ring.md","mtime":"2017-10-31T08:26:00.331Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2017-10-31T08:26:38.332Z"},"basePath":"..","book":{"language":""}});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue