mirror of
https://github.com/metosin/reitit.git
synced 2025-12-31 05:38:25 +00:00
Build book from commit 15bfb7b475 [skip ci]
This commit is contained in:
parent
0558db4db6
commit
627454fb84
18 changed files with 8592 additions and 43 deletions
533
advanced/configuring_routers.html
Normal file
533
advanced/configuring_routers.html
Normal file
|
|
@ -0,0 +1,533 @@
|
|||
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="" >
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
||||
<title>Configuring 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="../ring/" />
|
||||
|
||||
|
||||
<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/different_routers.html">
|
||||
|
||||
<a href="../basics/different_routers.html">
|
||||
|
||||
|
||||
Different Routers
|
||||
|
||||
</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_conflicts.html">
|
||||
|
||||
<a href="route_conflicts.html">
|
||||
|
||||
|
||||
Route conflicts
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.3.2" data-path="route_validation.html">
|
||||
|
||||
<a href="route_validation.html">
|
||||
|
||||
|
||||
Route Validation
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter active" 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/parameter_coercion.html">
|
||||
|
||||
<a href="../ring/parameter_coercion.html">
|
||||
|
||||
|
||||
Parameter coercion
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.4" 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=".." >Configuring 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">
|
||||
|
||||
<h2 id="configuring-routers">Configuring Routers</h2>
|
||||
<p>Routers can be configured via options. Options allow things like <a href="https://clojure.org/about/spec" target="_blank"><code>clojure.spec</code></a> validation for meta-data and fast, compiled handlers. The following options are available for the <code>reitit.core/router</code>:</p>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>key</th>
|
||||
<th>description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><code>:path</code></td>
|
||||
<td>Base-path for routes</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>:routes</code></td>
|
||||
<td>Initial resolved routes (default <code>[]</code>)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>:meta</code></td>
|
||||
<td>Initial expanded route-meta vector (default <code>[]</code>)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>:expand</code></td>
|
||||
<td>Function of <code>arg opts => meta</code> to expand route arg to route meta-data (default <code>reitit.core/expand</code>)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>:coerce</code></td>
|
||||
<td>Function of <code>route opts => route</code> to coerce resolved route, can throw or return <code>nil</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>:compile</code></td>
|
||||
<td>Function of <code>route opts => result</code> to compile a route handler</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>:conflicts</code></td>
|
||||
<td>Function of <code>{route #{route}} => side-effect</code> to handle conflicting routes (default <code>reitit.core/throw-on-conflicts!</code>)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>:router</code></td>
|
||||
<td>Function of <code>routes opts => router</code> to override the actual router implementation</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
</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="../ring/" class="navigation navigation-next " aria-label="Next page: Ring">
|
||||
<i class="fa fa-angle-right"></i>
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<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":""}});
|
||||
});
|
||||
</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>
|
||||
|
||||
495
advanced/index.html
Normal file
495
advanced/index.html
Normal file
|
|
@ -0,0 +1,495 @@
|
|||
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="" >
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
||||
<title>Advanced · 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="route_conflicts.html" />
|
||||
|
||||
|
||||
<link rel="prev" href="../basics/different_routers.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/different_routers.html">
|
||||
|
||||
<a href="../basics/different_routers.html">
|
||||
|
||||
|
||||
Different Routers
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter active" data-level="1.3" data-path="./">
|
||||
|
||||
<a href="./">
|
||||
|
||||
|
||||
Advanced
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
<ul class="articles">
|
||||
|
||||
|
||||
<li class="chapter " data-level="1.3.1" data-path="route_conflicts.html">
|
||||
|
||||
<a href="route_conflicts.html">
|
||||
|
||||
|
||||
Route conflicts
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.3.2" data-path="route_validation.html">
|
||||
|
||||
<a href="route_validation.html">
|
||||
|
||||
|
||||
Route Validation
|
||||
|
||||
</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/parameter_coercion.html">
|
||||
|
||||
<a href="../ring/parameter_coercion.html">
|
||||
|
||||
|
||||
Parameter coercion
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.4" 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=".." >Advanced</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="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>
|
||||
</ul>
|
||||
|
||||
|
||||
</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="../basics/different_routers.html" class="navigation navigation-prev " aria-label="Previous page: Different Routers">
|
||||
<i class="fa fa-angle-left"></i>
|
||||
</a>
|
||||
|
||||
|
||||
<a href="route_conflicts.html" class="navigation navigation-next " aria-label="Next page: Route conflicts">
|
||||
<i class="fa fa-angle-right"></i>
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<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":""}});
|
||||
});
|
||||
</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>
|
||||
|
||||
534
advanced/route_conflicts.html
Normal file
534
advanced/route_conflicts.html
Normal file
|
|
@ -0,0 +1,534 @@
|
|||
|
||||
<!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="route_validation.html" />
|
||||
|
||||
|
||||
<link rel="prev" href="./" />
|
||||
|
||||
|
||||
</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/different_routers.html">
|
||||
|
||||
<a href="../basics/different_routers.html">
|
||||
|
||||
|
||||
Different Routers
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.3" data-path="./">
|
||||
|
||||
<a href="./">
|
||||
|
||||
|
||||
Advanced
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
<ul class="articles">
|
||||
|
||||
|
||||
<li class="chapter active" data-level="1.3.1" data-path="route_conflicts.html">
|
||||
|
||||
<a href="route_conflicts.html">
|
||||
|
||||
|
||||
Route conflicts
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.3.2" data-path="route_validation.html">
|
||||
|
||||
<a href="route_validation.html">
|
||||
|
||||
|
||||
Route Validation
|
||||
|
||||
</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/parameter_coercion.html">
|
||||
|
||||
<a href="../ring/parameter_coercion.html">
|
||||
|
||||
|
||||
Parameter coercion
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.4" 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 single path lookup could match multiple routes. Usually, first match is used. This is not good, especially if route tree is merged from multiple sources - routes might regress to be unreachable without a warning.</p>
|
||||
<p>Reitit resolves this by running explicit conflicit resolution when a <code>Router</code> is created. Conflicting routes are passed into a <code>:conflicts</code> callback. Default implementation throws <code>ex-info</code> with a descriptive message.</p>
|
||||
<p>Examples routes with conflicts:</p>
|
||||
<pre><code class="lang-clj">(<span class="hljs-name">require</span> '[reitit.core <span class="hljs-symbol">:as</span> reitit])
|
||||
|
||||
(<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">reitit/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">reitit/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="./" class="navigation navigation-prev " aria-label="Previous page: Advanced">
|
||||
<i class="fa fa-angle-left"></i>
|
||||
</a>
|
||||
|
||||
|
||||
<a href="route_validation.html" class="navigation navigation-next " aria-label="Next page: Route Validation">
|
||||
<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.3.1","depth":2,"next":{"title":"Route Validation","level":"1.3.2","depth":2,"path":"advanced/route_validation.md","ref":"advanced/route_validation.md","articles":[]},"previous":{"title":"Advanced","level":"1.3","depth":1,"path":"advanced/README.md","ref":"advanced/README.md","articles":[{"title":"Route conflicts","level":"1.3.1","depth":2,"path":"advanced/route_conflicts.md","ref":"advanced/route_conflicts.md","articles":[]},{"title":"Route Validation","level":"1.3.2","depth":2,"path":"advanced/route_validation.md","ref":"advanced/route_validation.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_conflicts.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":""}});
|
||||
});
|
||||
</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>
|
||||
|
||||
644
advanced/route_validation.html
Normal file
644
advanced/route_validation.html
Normal file
|
|
@ -0,0 +1,644 @@
|
|||
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="" >
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
||||
<title>Route Validation · 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_conflicts.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/different_routers.html">
|
||||
|
||||
<a href="../basics/different_routers.html">
|
||||
|
||||
|
||||
Different Routers
|
||||
|
||||
</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_conflicts.html">
|
||||
|
||||
<a href="route_conflicts.html">
|
||||
|
||||
|
||||
Route conflicts
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter active" data-level="1.3.2" data-path="route_validation.html">
|
||||
|
||||
<a href="route_validation.html">
|
||||
|
||||
|
||||
Route Validation
|
||||
|
||||
</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/parameter_coercion.html">
|
||||
|
||||
<a href="../ring/parameter_coercion.html">
|
||||
|
||||
|
||||
Parameter coercion
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.4" 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 Validation</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-validation">Route validation</h1>
|
||||
<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>
|
||||
</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>
|
||||
<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])
|
||||
|
||||
(<span class="hljs-name"><span class="hljs-builtin-name">def</span></span> routes-from-db
|
||||
[<span class="hljs-string">"tenant1"</span> <span class="hljs-symbol">::tenant1</span>])
|
||||
|
||||
(<span class="hljs-name">s/valid?</span> <span class="hljs-symbol">::spec/raw-routes</span> routes-from-db)
|
||||
<span class="hljs-comment">; false</span>
|
||||
|
||||
(<span class="hljs-name">s/explain</span> <span class="hljs-symbol">::spec/raw-routes</span> routes-from-db)
|
||||
<span class="hljs-comment">; In: [0] val: "tenant1" fails spec: :reitit.spec/path at: [:route :path] predicate: (or (blank? %) (starts-with? % "/"))</span>
|
||||
<span class="hljs-comment">; In: [0] val: "tenant1" fails spec: :reitit.spec/raw-route at: [:routes] predicate: (cat :path :reitit.spec/path :arg (? :reitit.spec/arg) :childs (* (and (nilable :reitit.spec/raw-route))))</span>
|
||||
<span class="hljs-comment">; In: [1] val: :user/tenant1 fails spec: :reitit.spec/raw-route at: [:routes] predicate: (cat :path :reitit.spec/path :arg (? :reitit.spec/arg) :childs (* (and (nilable :reitit.spec/raw-route))))</span>
|
||||
<span class="hljs-comment">; :clojure.spec.alpha/spec :reitit.spec/raw-routes</span>
|
||||
<span class="hljs-comment">; :clojure.spec.alpha/value ["tenant1" :user/tenant1]</span>
|
||||
</code></pre>
|
||||
<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>]
|
||||
</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])
|
||||
(<span class="hljs-name">require</span> '[expound.alpha <span class="hljs-symbol">:as</span> expound])
|
||||
(<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-name">stest/instrument</span> `reitit/router)
|
||||
(<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>
|
||||
[<span class="hljs-string">"/api"</span>
|
||||
[<span class="hljs-string">"/public"</span>
|
||||
[<span class="hljs-string">"/ping"</span>]
|
||||
[<span class="hljs-string">"pong"</span>]]])
|
||||
|
||||
<span class="hljs-comment">; CompilerException clojure.lang.ExceptionInfo: Call to #'reitit.core/router did not conform to spec:</span>
|
||||
<span class="hljs-comment">;</span>
|
||||
<span class="hljs-comment">; -- Spec failed --------------------</span>
|
||||
<span class="hljs-comment">;</span>
|
||||
<span class="hljs-comment">; Function arguments</span>
|
||||
<span class="hljs-comment">;</span>
|
||||
<span class="hljs-comment">; (["/api" ...])</span>
|
||||
<span class="hljs-comment">; ^^^^^^</span>
|
||||
<span class="hljs-comment">;</span>
|
||||
<span class="hljs-comment">; should satisfy</span>
|
||||
<span class="hljs-comment">;</span>
|
||||
<span class="hljs-comment">; (clojure.spec.alpha/cat</span>
|
||||
<span class="hljs-comment">; :path</span>
|
||||
<span class="hljs-comment">; :reitit.spec/path</span>
|
||||
<span class="hljs-comment">; :arg</span>
|
||||
<span class="hljs-comment">; (clojure.spec.alpha/? :reitit.spec/arg)</span>
|
||||
<span class="hljs-comment">; :childs</span>
|
||||
<span class="hljs-comment">; (clojure.spec.alpha/*</span>
|
||||
<span class="hljs-comment">; (clojure.spec.alpha/and</span>
|
||||
<span class="hljs-comment">; (clojure.spec.alpha/nilable :reitit.spec/raw-route))))</span>
|
||||
<span class="hljs-comment">;</span>
|
||||
<span class="hljs-comment">; or</span>
|
||||
<span class="hljs-comment">;</span>
|
||||
<span class="hljs-comment">; (clojure.spec.alpha/cat</span>
|
||||
<span class="hljs-comment">; :path</span>
|
||||
<span class="hljs-comment">; :reitit.spec/path</span>
|
||||
<span class="hljs-comment">; :arg</span>
|
||||
<span class="hljs-comment">; (clojure.spec.alpha/? :reitit.spec/arg)</span>
|
||||
<span class="hljs-comment">; :childs</span>
|
||||
<span class="hljs-comment">; (clojure.spec.alpha/*</span>
|
||||
<span class="hljs-comment">; (clojure.spec.alpha/and</span>
|
||||
<span class="hljs-comment">; (clojure.spec.alpha/nilable :reitit.spec/raw-route))))</span>
|
||||
<span class="hljs-comment">;</span>
|
||||
<span class="hljs-comment">; -- Relevant specs -------</span>
|
||||
<span class="hljs-comment">;</span>
|
||||
<span class="hljs-comment">; :reitit.spec/raw-route:</span>
|
||||
<span class="hljs-comment">; (clojure.spec.alpha/cat</span>
|
||||
<span class="hljs-comment">; :path</span>
|
||||
<span class="hljs-comment">; :reitit.spec/path</span>
|
||||
<span class="hljs-comment">; :arg</span>
|
||||
<span class="hljs-comment">; (clojure.spec.alpha/? :reitit.spec/arg)</span>
|
||||
<span class="hljs-comment">; :childs</span>
|
||||
<span class="hljs-comment">; (clojure.spec.alpha/*</span>
|
||||
<span class="hljs-comment">; (clojure.spec.alpha/and</span>
|
||||
<span class="hljs-comment">; (clojure.spec.alpha/nilable :reitit.spec/raw-route))))</span>
|
||||
<span class="hljs-comment">; :reitit.spec/raw-routes:</span>
|
||||
<span class="hljs-comment">; (clojure.spec.alpha/or</span>
|
||||
<span class="hljs-comment">; :route</span>
|
||||
<span class="hljs-comment">; :reitit.spec/raw-route</span>
|
||||
<span class="hljs-comment">; :routes</span>
|
||||
<span class="hljs-comment">; (clojure.spec.alpha/coll-of :reitit.spec/raw-route :into []))</span>
|
||||
<span class="hljs-comment">;</span>
|
||||
<span class="hljs-comment">; -- Spec failed --------------------</span>
|
||||
<span class="hljs-comment">;</span>
|
||||
<span class="hljs-comment">; Function arguments</span>
|
||||
<span class="hljs-comment">;</span>
|
||||
<span class="hljs-comment">; ([... [... ... ["pong"]]])</span>
|
||||
<span class="hljs-comment">; ^^^^^^</span>
|
||||
<span class="hljs-comment">;</span>
|
||||
<span class="hljs-comment">; should satisfy</span>
|
||||
<span class="hljs-comment">;</span>
|
||||
<span class="hljs-comment">; (fn</span>
|
||||
<span class="hljs-comment">; [%]</span>
|
||||
<span class="hljs-comment">; (or</span>
|
||||
<span class="hljs-comment">; (clojure.string/blank? %)</span>
|
||||
<span class="hljs-comment">; (clojure.string/starts-with? % "/")))</span>
|
||||
<span class="hljs-comment">;</span>
|
||||
<span class="hljs-comment">; or</span>
|
||||
<span class="hljs-comment">;</span>
|
||||
<span class="hljs-comment">; (fn</span>
|
||||
<span class="hljs-comment">; [%]</span>
|
||||
<span class="hljs-comment">; (or</span>
|
||||
<span class="hljs-comment">; (clojure.string/blank? %)</span>
|
||||
<span class="hljs-comment">; (clojure.string/starts-with? % "/")))</span>
|
||||
<span class="hljs-comment">;</span>
|
||||
<span class="hljs-comment">; -- Relevant specs -------</span>
|
||||
<span class="hljs-comment">;</span>
|
||||
<span class="hljs-comment">; :reitit.spec/path:</span>
|
||||
<span class="hljs-comment">; (clojure.spec.alpha/and</span>
|
||||
<span class="hljs-comment">; clojure.core/string?</span>
|
||||
<span class="hljs-comment">; (clojure.core/fn</span>
|
||||
<span class="hljs-comment">; [%]</span>
|
||||
<span class="hljs-comment">; (clojure.core/or</span>
|
||||
<span class="hljs-comment">; (clojure.string/blank? %)</span>
|
||||
<span class="hljs-comment">; (clojure.string/starts-with? % "/"))))</span>
|
||||
<span class="hljs-comment">; :reitit.spec/raw-route:</span>
|
||||
<span class="hljs-comment">; (clojure.spec.alpha/cat</span>
|
||||
<span class="hljs-comment">; :path</span>
|
||||
<span class="hljs-comment">; :reitit.spec/path</span>
|
||||
<span class="hljs-comment">; :arg</span>
|
||||
<span class="hljs-comment">; (clojure.spec.alpha/? :reitit.spec/arg)</span>
|
||||
<span class="hljs-comment">; :childs</span>
|
||||
<span class="hljs-comment">; (clojure.spec.alpha/*</span>
|
||||
<span class="hljs-comment">; (clojure.spec.alpha/and</span>
|
||||
<span class="hljs-comment">; (clojure.spec.alpha/nilable :reitit.spec/raw-route))))</span>
|
||||
<span class="hljs-comment">; :reitit.spec/raw-routes:</span>
|
||||
<span class="hljs-comment">; (clojure.spec.alpha/or</span>
|
||||
<span class="hljs-comment">; :route</span>
|
||||
<span class="hljs-comment">; :reitit.spec/raw-route</span>
|
||||
<span class="hljs-comment">; :routes</span>
|
||||
<span class="hljs-comment">; (clojure.spec.alpha/coll-of :reitit.spec/raw-route :into []))</span>
|
||||
<span class="hljs-comment">;</span>
|
||||
<span class="hljs-comment">; -------------------------</span>
|
||||
<span class="hljs-comment">; Detected 2 errors</span>
|
||||
</code></pre>
|
||||
<h1 id="validating-route-data">Validating route data</h1>
|
||||
<p><em>TODO</em></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="route_conflicts.html" class="navigation navigation-prev " aria-label="Previous page: Route conflicts">
|
||||
<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":"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":""}});
|
||||
});
|
||||
</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>
|
||||
|
||||
521
basics/different_routers.html
Normal file
521
basics/different_routers.html
Normal file
|
|
@ -0,0 +1,521 @@
|
|||
|
||||
<!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="../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="different_routers.html">
|
||||
|
||||
<a href="different_routers.html">
|
||||
|
||||
|
||||
Different Routers
|
||||
|
||||
</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_conflicts.html">
|
||||
|
||||
<a href="../advanced/route_conflicts.html">
|
||||
|
||||
|
||||
Route conflicts
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.3.2" data-path="../advanced/route_validation.html">
|
||||
|
||||
<a href="../advanced/route_validation.html">
|
||||
|
||||
|
||||
Route Validation
|
||||
|
||||
</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/parameter_coercion.html">
|
||||
|
||||
<a href="../ring/parameter_coercion.html">
|
||||
|
||||
|
||||
Parameter coercion
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.4" 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 awesome <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> ROUTER OPTION.</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>Fastest 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 CONFLICTING ROUTES.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>:prefix-tree-router</code></td>
|
||||
<td><a href="https://github.com/julienschmidt/httprouter#how-does-it-work" target="_blank">TODO</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_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":"Different Routers","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 conflicts","level":"1.3.1","depth":2,"path":"advanced/route_conflicts.md","ref":"advanced/route_conflicts.md","articles":[]},{"title":"Route Validation","level":"1.3.2","depth":2,"path":"advanced/route_validation.md","ref":"advanced/route_validation.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/different_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":""}});
|
||||
});
|
||||
</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>
|
||||
|
||||
498
basics/index.html
Normal file
498
basics/index.html
Normal file
|
|
@ -0,0 +1,498 @@
|
|||
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="" >
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
||||
<title>Basics · 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="route_syntax.html" />
|
||||
|
||||
|
||||
<link rel="prev" href="../" />
|
||||
|
||||
|
||||
</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 active" 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 " data-level="1.2.6" data-path="different_routers.html">
|
||||
|
||||
<a href="different_routers.html">
|
||||
|
||||
|
||||
Different Routers
|
||||
|
||||
</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_conflicts.html">
|
||||
|
||||
<a href="../advanced/route_conflicts.html">
|
||||
|
||||
|
||||
Route conflicts
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.3.2" data-path="../advanced/route_validation.html">
|
||||
|
||||
<a href="../advanced/route_validation.html">
|
||||
|
||||
|
||||
Route Validation
|
||||
|
||||
</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/parameter_coercion.html">
|
||||
|
||||
<a href="../ring/parameter_coercion.html">
|
||||
|
||||
|
||||
Parameter coercion
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.4" 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=".." >Basics</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="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>
|
||||
</ul>
|
||||
|
||||
|
||||
</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="../" class="navigation navigation-prev " aria-label="Previous page: Introduction">
|
||||
<i class="fa fa-angle-left"></i>
|
||||
</a>
|
||||
|
||||
|
||||
<a href="route_syntax.html" class="navigation navigation-next " aria-label="Next page: Route syntax">
|
||||
<i class="fa fa-angle-right"></i>
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<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":""}});
|
||||
});
|
||||
</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>
|
||||
|
||||
518
basics/name_based_routing.html
Normal file
518
basics/name_based_routing.html
Normal file
|
|
@ -0,0 +1,518 @@
|
|||
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="" >
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
||||
<title>Name-based Routing · 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="route_data.html" />
|
||||
|
||||
|
||||
<link rel="prev" href="path_based_routing.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 active" 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 " data-level="1.2.6" data-path="different_routers.html">
|
||||
|
||||
<a href="different_routers.html">
|
||||
|
||||
|
||||
Different Routers
|
||||
|
||||
</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_conflicts.html">
|
||||
|
||||
<a href="../advanced/route_conflicts.html">
|
||||
|
||||
|
||||
Route conflicts
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.3.2" data-path="../advanced/route_validation.html">
|
||||
|
||||
<a href="../advanced/route_validation.html">
|
||||
|
||||
|
||||
Route Validation
|
||||
|
||||
</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/parameter_coercion.html">
|
||||
|
||||
<a href="../ring/parameter_coercion.html">
|
||||
|
||||
|
||||
Parameter coercion
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.4" 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=".." >Name-based Routing</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">
|
||||
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
<span class="hljs-comment">; :result nil,</span>
|
||||
<span class="hljs-comment">; :params nil,</span>
|
||||
<span class="hljs-comment">; :required #{:id}}</span>
|
||||
|
||||
(<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>
|
||||
<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>
|
||||
<span class="hljs-comment">; :path "/api/user/1"</span>
|
||||
<span class="hljs-comment">; :result nil</span>
|
||||
<span class="hljs-comment">; :params {:id "1"}}</span>
|
||||
</code></pre>
|
||||
<p>There is also a exception throwing version:</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">; ExceptionInfo missing path-params for route /api/user/:id: #{:id}</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="path_based_routing.html" class="navigation navigation-prev " aria-label="Previous page: Path-based Routing">
|
||||
<i class="fa fa-angle-left"></i>
|
||||
</a>
|
||||
|
||||
|
||||
<a href="route_data.html" class="navigation navigation-next " aria-label="Next page: Route data">
|
||||
<i class="fa fa-angle-right"></i>
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<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":""}});
|
||||
});
|
||||
</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>
|
||||
|
||||
506
basics/path_based_routing.html
Normal file
506
basics/path_based_routing.html
Normal file
|
|
@ -0,0 +1,506 @@
|
|||
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="" >
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
||||
<title>Path-based Routing · 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="name_based_routing.html" />
|
||||
|
||||
|
||||
<link rel="prev" href="router.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 active" 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 " data-level="1.2.6" data-path="different_routers.html">
|
||||
|
||||
<a href="different_routers.html">
|
||||
|
||||
|
||||
Different Routers
|
||||
|
||||
</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_conflicts.html">
|
||||
|
||||
<a href="../advanced/route_conflicts.html">
|
||||
|
||||
|
||||
Route conflicts
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.3.2" data-path="../advanced/route_validation.html">
|
||||
|
||||
<a href="../advanced/route_validation.html">
|
||||
|
||||
|
||||
Route Validation
|
||||
|
||||
</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/parameter_coercion.html">
|
||||
|
||||
<a href="../ring/parameter_coercion.html">
|
||||
|
||||
|
||||
Parameter coercion
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.4" 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=".." >Path-based Routing</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">
|
||||
|
||||
<h2 id="path-based-routing">Path-based routing</h2>
|
||||
<p>Path-based routing is done using the <code>reitit.core/match-by-path</code> function. It takes the router and path as arguments and returns one of the following:</p>
|
||||
<ul>
|
||||
<li><code>nil</code>, no match</li>
|
||||
<li><code>PartialMatch</code>, path matched, missing path-parameters (only in reverse-routing)</li>
|
||||
<li><code>Match</code>, exact match</li>
|
||||
</ul>
|
||||
<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>
|
||||
<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>
|
||||
<span class="hljs-comment">; :path "/api/user/1"</span>
|
||||
<span class="hljs-comment">; :result nil</span>
|
||||
<span class="hljs-comment">; :params {:id "1"}}</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="router.html" class="navigation navigation-prev " aria-label="Previous page: Router">
|
||||
<i class="fa fa-angle-left"></i>
|
||||
</a>
|
||||
|
||||
|
||||
<a href="name_based_routing.html" class="navigation navigation-next " aria-label="Next page: Name-based Routing">
|
||||
<i class="fa fa-angle-right"></i>
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<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":""}});
|
||||
});
|
||||
</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>
|
||||
|
||||
531
basics/route_data.html
Normal file
531
basics/route_data.html
Normal file
|
|
@ -0,0 +1,531 @@
|
|||
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="" >
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
||||
<title>Route data · 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="different_routers.html" />
|
||||
|
||||
|
||||
<link rel="prev" href="name_based_routing.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 active" data-level="1.2.5" data-path="route_data.html">
|
||||
|
||||
<a href="route_data.html">
|
||||
|
||||
|
||||
Route data
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.2.6" data-path="different_routers.html">
|
||||
|
||||
<a href="different_routers.html">
|
||||
|
||||
|
||||
Different Routers
|
||||
|
||||
</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_conflicts.html">
|
||||
|
||||
<a href="../advanced/route_conflicts.html">
|
||||
|
||||
|
||||
Route conflicts
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.3.2" data-path="../advanced/route_validation.html">
|
||||
|
||||
<a href="../advanced/route_validation.html">
|
||||
|
||||
|
||||
Route Validation
|
||||
|
||||
</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/parameter_coercion.html">
|
||||
|
||||
<a href="../ring/parameter_coercion.html">
|
||||
|
||||
|
||||
Parameter coercion
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.4" 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 data</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-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>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>
|
||||
[<span class="hljs-string">"/api"</span> {<span class="hljs-symbol">:interceptors</span> [<span class="hljs-symbol">::api</span>]}
|
||||
[<span class="hljs-string">"/ping"</span> <span class="hljs-symbol">::ping</span>]
|
||||
[<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>]]]]]))
|
||||
</code></pre>
|
||||
<p>Resolved route tree:</p>
|
||||
<pre><code class="lang-clj">(<span class="hljs-name">reitit/routes</span> router)
|
||||
<span class="hljs-comment">; [["/api/ping" {:interceptors [::api]</span>
|
||||
<span class="hljs-comment">; :name ::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>
|
||||
</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>
|
||||
<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>
|
||||
</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="name_based_routing.html" class="navigation navigation-prev " aria-label="Previous page: Name-based Routing">
|
||||
<i class="fa fa-angle-left"></i>
|
||||
</a>
|
||||
|
||||
|
||||
<a href="different_routers.html" class="navigation navigation-next " aria-label="Next page: Different Routers">
|
||||
<i class="fa fa-angle-right"></i>
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<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":""}});
|
||||
});
|
||||
</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>
|
||||
|
||||
543
basics/route_syntax.html
Normal file
543
basics/route_syntax.html
Normal file
|
|
@ -0,0 +1,543 @@
|
|||
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="" >
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
||||
<title>Route syntax · 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="router.html" />
|
||||
|
||||
|
||||
<link rel="prev" href="./" />
|
||||
|
||||
|
||||
</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 active" 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 " data-level="1.2.6" data-path="different_routers.html">
|
||||
|
||||
<a href="different_routers.html">
|
||||
|
||||
|
||||
Different Routers
|
||||
|
||||
</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_conflicts.html">
|
||||
|
||||
<a href="../advanced/route_conflicts.html">
|
||||
|
||||
|
||||
Route conflicts
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.3.2" data-path="../advanced/route_validation.html">
|
||||
|
||||
<a href="../advanced/route_validation.html">
|
||||
|
||||
|
||||
Route Validation
|
||||
|
||||
</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/parameter_coercion.html">
|
||||
|
||||
<a href="../ring/parameter_coercion.html">
|
||||
|
||||
|
||||
Parameter coercion
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.4" 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 syntax</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-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>Simple route:</p>
|
||||
<pre><code class="lang-clj">[<span class="hljs-string">"/ping"</span>]
|
||||
</code></pre>
|
||||
<p>Two routes:</p>
|
||||
<pre><code class="lang-clj">[[<span class="hljs-string">"/ping"</span>]
|
||||
[<span class="hljs-string">"/pong"</span>]]
|
||||
</code></pre>
|
||||
<p>Routes with route arguments:</p>
|
||||
<pre><code class="lang-clj">[[<span class="hljs-string">"/ping"</span> <span class="hljs-symbol">::ping</span>]
|
||||
[<span class="hljs-string">"/pong"</span> {<span class="hljs-symbol">:name</span> <span class="hljs-symbol">::pong</span>}]]
|
||||
</code></pre>
|
||||
<p>Routes with path parameters:</p>
|
||||
<pre><code class="lang-clj">[[<span class="hljs-string">"/users/:user-id"</span>]
|
||||
[<span class="hljs-string">"/api/:version/ping"</span>]]
|
||||
</code></pre>
|
||||
<p>Route with catch-all parameter:</p>
|
||||
<pre><code class="lang-clj">[<span class="hljs-string">"/public/*path"</span>]
|
||||
</code></pre>
|
||||
<p>Nested routes:</p>
|
||||
<pre><code class="lang-clj">[<span class="hljs-string">"/api"</span>
|
||||
[<span class="hljs-string">"/admin"</span> {<span class="hljs-symbol">:middleware</span> [<span class="hljs-symbol">::admin</span>]}
|
||||
[<span class="hljs-string">""</span> <span class="hljs-symbol">::admin</span>]
|
||||
[<span class="hljs-string">"/db"</span> <span class="hljs-symbol">::db</span>]]
|
||||
[<span class="hljs-string">"/ping"</span> <span class="hljs-symbol">::ping</span>]]
|
||||
</code></pre>
|
||||
<p>Same routes flattened:</p>
|
||||
<pre><code class="lang-clj">[[<span class="hljs-string">"/api/admin"</span> {<span class="hljs-symbol">:middleware</span> [<span class="hljs-symbol">::admin</span>], <span class="hljs-symbol">:name</span> <span class="hljs-symbol">::admin</span>}]
|
||||
[<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>
|
||||
<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
|
||||
<span class="hljs-symbol">:let</span> [path (<span class="hljs-name"><span class="hljs-builtin-name">str</span></span> <span class="hljs-string">"/"</span> (<span class="hljs-name"><span class="hljs-builtin-name">name</span></span> interceptor))
|
||||
method (<span class="hljs-name"><span class="hljs-builtin-name">condp</span></span> = type
|
||||
<span class="hljs-symbol">:query</span> <span class="hljs-symbol">:get</span>
|
||||
<span class="hljs-symbol">:command</span> <span class="hljs-symbol">:post</span>)]]
|
||||
[path {method {<span class="hljs-symbol">:interceptors</span> [interceptor]}}])
|
||||
(<span class="hljs-name"><span class="hljs-builtin-name">if</span></span> dev-mode? [<span class="hljs-string">"/dev-tools"</span> <span class="hljs-symbol">::dev-tools</span>])])
|
||||
</code></pre>
|
||||
<pre><code class="lang-clj">(<span class="hljs-name">cqrs-routes</span>
|
||||
[[<span class="hljs-symbol">:query</span> 'get-user]
|
||||
[<span class="hljs-symbol">:command</span> 'add-user]
|
||||
[<span class="hljs-symbol">:command</span> 'add-order]]
|
||||
<span class="hljs-literal">false</span>)
|
||||
<span class="hljs-comment">; ["/api" {:interceptors [::api ::db]}</span>
|
||||
<span class="hljs-comment">; (["/get-user" {:get {:interceptors [get-user]}}]</span>
|
||||
<span class="hljs-comment">; ["/add-user" {:post {:interceptors [add-user]}}]</span>
|
||||
<span class="hljs-comment">; ["/add-order" {:post {:interceptors [add-order]}}])</span>
|
||||
<span class="hljs-comment">; nil]</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="./" class="navigation navigation-prev " aria-label="Previous page: Basics">
|
||||
<i class="fa fa-angle-left"></i>
|
||||
</a>
|
||||
|
||||
|
||||
<a href="router.html" class="navigation navigation-next " aria-label="Next page: Router">
|
||||
<i class="fa fa-angle-right"></i>
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<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":""}});
|
||||
});
|
||||
</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>
|
||||
|
||||
514
basics/router.html
Normal file
514
basics/router.html
Normal file
|
|
@ -0,0 +1,514 @@
|
|||
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="" >
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
||||
<title>Router · 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="path_based_routing.html" />
|
||||
|
||||
|
||||
<link rel="prev" href="route_syntax.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 active" 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 " data-level="1.2.6" data-path="different_routers.html">
|
||||
|
||||
<a href="different_routers.html">
|
||||
|
||||
|
||||
Different Routers
|
||||
|
||||
</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_conflicts.html">
|
||||
|
||||
<a href="../advanced/route_conflicts.html">
|
||||
|
||||
|
||||
Route conflicts
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.3.2" data-path="../advanced/route_validation.html">
|
||||
|
||||
<a href="../advanced/route_validation.html">
|
||||
|
||||
|
||||
Route Validation
|
||||
|
||||
</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/parameter_coercion.html">
|
||||
|
||||
<a href="../ring/parameter_coercion.html">
|
||||
|
||||
|
||||
Parameter coercion
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.4" 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=".." >Router</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="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>
|
||||
<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])
|
||||
(<span class="hljs-name">options</span> [this])
|
||||
(<span class="hljs-name">route-names</span> [this])
|
||||
(<span class="hljs-name">match-by-path</span> [this path])
|
||||
(<span class="hljs-name">match-by-name</span> [this name] [this name params]))
|
||||
</code></pre>
|
||||
<p>Creating 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>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>
|
||||
<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>
|
||||
|
||||
|
||||
</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_syntax.html" class="navigation navigation-prev " aria-label="Previous page: Route syntax">
|
||||
<i class="fa fa-angle-left"></i>
|
||||
</a>
|
||||
|
||||
|
||||
<a href="path_based_routing.html" class="navigation navigation-next " aria-label="Next page: Path-based Routing">
|
||||
<i class="fa fa-angle-right"></i>
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<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":""}});
|
||||
});
|
||||
</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>
|
||||
|
||||
90
index.html
90
index.html
|
|
@ -57,6 +57,8 @@
|
|||
<link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">
|
||||
|
||||
|
||||
<link rel="next" href="basics/" />
|
||||
|
||||
|
||||
|
||||
</head>
|
||||
|
|
@ -98,23 +100,23 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.2" >
|
||||
<li class="chapter " data-level="1.2" data-path="basics/">
|
||||
|
||||
<span>
|
||||
<a href="basics/">
|
||||
|
||||
|
||||
Basics
|
||||
|
||||
</span>
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
<ul class="articles">
|
||||
|
||||
|
||||
<li class="chapter " data-level="1.2.1" data-path="basics.html">
|
||||
<li class="chapter " data-level="1.2.1" data-path="basics/route_syntax.html">
|
||||
|
||||
<a href="basics.html#route-syntax">
|
||||
<a href="basics/route_syntax.html">
|
||||
|
||||
|
||||
Route syntax
|
||||
|
|
@ -125,9 +127,9 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.2.2" data-path="basics.html">
|
||||
<li class="chapter " data-level="1.2.2" data-path="basics/router.html">
|
||||
|
||||
<a href="basics.html#router">
|
||||
<a href="basics/router.html">
|
||||
|
||||
|
||||
Router
|
||||
|
|
@ -138,9 +140,9 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.2.3" data-path="basics.html">
|
||||
<li class="chapter " data-level="1.2.3" data-path="basics/path_based_routing.html">
|
||||
|
||||
<a href="basics.html#path-based-routing">
|
||||
<a href="basics/path_based_routing.html">
|
||||
|
||||
|
||||
Path-based Routing
|
||||
|
|
@ -151,9 +153,9 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.2.4" data-path="basics.html">
|
||||
<li class="chapter " data-level="1.2.4" data-path="basics/name_based_routing.html">
|
||||
|
||||
<a href="basics.html#name-based-routing">
|
||||
<a href="basics/name_based_routing.html">
|
||||
|
||||
|
||||
Name-based Routing
|
||||
|
|
@ -164,9 +166,9 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.2.5" data-path="basics.html">
|
||||
<li class="chapter " data-level="1.2.5" data-path="basics/route_data.html">
|
||||
|
||||
<a href="basics.html#route-data">
|
||||
<a href="basics/route_data.html">
|
||||
|
||||
|
||||
Route data
|
||||
|
|
@ -177,9 +179,9 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.2.6" data-path="basics.html">
|
||||
<li class="chapter " data-level="1.2.6" data-path="basics/different_routers.html">
|
||||
|
||||
<a href="basics.html#different-routers">
|
||||
<a href="basics/different_routers.html">
|
||||
|
||||
|
||||
Different Routers
|
||||
|
|
@ -195,23 +197,23 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.3" >
|
||||
<li class="chapter " data-level="1.3" data-path="advanced/">
|
||||
|
||||
<span>
|
||||
<a href="advanced/">
|
||||
|
||||
|
||||
Advanced
|
||||
|
||||
</span>
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
<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="advanced/route_conflicts.html">
|
||||
|
||||
<a href="route_conflicts.html">
|
||||
<a href="advanced/route_conflicts.html">
|
||||
|
||||
|
||||
Route conflicts
|
||||
|
|
@ -222,9 +224,9 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.3.2" data-path="route_validation.html">
|
||||
<li class="chapter " data-level="1.3.2" data-path="advanced/route_validation.html">
|
||||
|
||||
<a href="route_validation.html">
|
||||
<a href="advanced/route_validation.html">
|
||||
|
||||
|
||||
Route Validation
|
||||
|
|
@ -235,9 +237,9 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.3.3" data-path="configuring_routers.html">
|
||||
<li class="chapter " data-level="1.3.3" data-path="advanced/configuring_routers.html">
|
||||
|
||||
<a href="configuring_routers.html">
|
||||
<a href="advanced/configuring_routers.html">
|
||||
|
||||
|
||||
Configuring routers
|
||||
|
|
@ -253,23 +255,23 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4" >
|
||||
<li class="chapter " data-level="1.4" data-path="ring/">
|
||||
|
||||
<span>
|
||||
<a href="ring/">
|
||||
|
||||
|
||||
Ring
|
||||
|
||||
</span>
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
<ul class="articles">
|
||||
|
||||
|
||||
<li class="chapter " data-level="1.4.1" data-path="ring.html">
|
||||
<li class="chapter " data-level="1.4.1" data-path="ring/ring.html">
|
||||
|
||||
<a href="ring.html">
|
||||
<a href="ring/ring.html">
|
||||
|
||||
|
||||
Ring-router
|
||||
|
|
@ -280,9 +282,9 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.2" data-path="dynamic_extensions.html">
|
||||
<li class="chapter " data-level="1.4.2" data-path="ring/dynamic_extensions.html">
|
||||
|
||||
<a href="dynamic_extensions.html">
|
||||
<a href="ring/dynamic_extensions.html">
|
||||
|
||||
|
||||
Dynamic extensions
|
||||
|
|
@ -293,9 +295,9 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.3" data-path="parameter_coercion.html">
|
||||
<li class="chapter " data-level="1.4.3" data-path="ring/parameter_coercion.html">
|
||||
|
||||
<a href="parameter_coercion.html">
|
||||
<a href="ring/parameter_coercion.html">
|
||||
|
||||
|
||||
Parameter coercion
|
||||
|
|
@ -306,9 +308,9 @@
|
|||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.4" data-path="compiling_middleware.html">
|
||||
<li class="chapter " data-level="1.4.4" data-path="ring/compiling_middleware.html">
|
||||
|
||||
<a href="compiling_middleware.html">
|
||||
<a href="ring/compiling_middleware.html">
|
||||
|
||||
|
||||
Compiling middleware
|
||||
|
|
@ -398,12 +400,12 @@
|
|||
<h1 id="introduction">Introduction</h1>
|
||||
<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.html#route-syntax">route syntax</a></li>
|
||||
<li>First-class <a href="basics.html#route-data">route meta-data</a></li>
|
||||
<li>Bi-directional-routing</li>
|
||||
<li><a href="route_conflicts.html">Route conflict resolution</a></li>
|
||||
<li><a href="parameter_coercion.html">Pluggable coercion</a> (<a href="https://clojure.org/about/spec" target="_blank">clojure.spec</a>)</li>
|
||||
<li>Both <a href="ring.html#middleware">Middleware</a> & Interceptors</li>
|
||||
<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>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>
|
||||
<li>supports both <a href="ring/compiling_middleware.html">Middleware</a> & Interceptors</li>
|
||||
<li>Extendable</li>
|
||||
<li>Fast</li>
|
||||
</ul>
|
||||
|
|
@ -533,6 +535,10 @@
|
|||
|
||||
|
||||
|
||||
<a href="basics/" class="navigation navigation-next navigation-unique" aria-label="Next page: Basics">
|
||||
<i class="fa fa-angle-right"></i>
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
|
@ -540,7 +546,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,"ref":"","articles":[{"title":"Route syntax","level":"1.2.1","depth":2,"anchor":"#route-syntax","path":"basics.md","ref":"basics.md#route-syntax","articles":[]},{"title":"Router","level":"1.2.2","depth":2,"anchor":"#router","path":"basics.md","ref":"basics.md#router","articles":[]},{"title":"Path-based Routing","level":"1.2.3","depth":2,"anchor":"#path-based-routing","path":"basics.md","ref":"basics.md#path-based-routing","articles":[]},{"title":"Name-based Routing","level":"1.2.4","depth":2,"anchor":"#name-based-routing","path":"basics.md","ref":"basics.md#name-based-routing","articles":[]},{"title":"Route data","level":"1.2.5","depth":2,"anchor":"#route-data","path":"basics.md","ref":"basics.md#route-data","articles":[]},{"title":"Different Routers","level":"1.2.6","depth":2,"anchor":"#different-routers","path":"basics.md","ref":"basics.md#different-routers","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-25T15:00:22.836Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2017-10-25T15:01:14.084Z"},"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":"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":""}});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
|
|
|||
546
ring/compiling_middleware.html
Normal file
546
ring/compiling_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>Compiling 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="prev" href="parameter_coercion.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/different_routers.html">
|
||||
|
||||
<a href="../basics/different_routers.html">
|
||||
|
||||
|
||||
Different Routers
|
||||
|
||||
</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_conflicts.html">
|
||||
|
||||
<a href="../advanced/route_conflicts.html">
|
||||
|
||||
|
||||
Route conflicts
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.3.2" data-path="../advanced/route_validation.html">
|
||||
|
||||
<a href="../advanced/route_validation.html">
|
||||
|
||||
|
||||
Route Validation
|
||||
|
||||
</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 " data-level="1.4.3" data-path="parameter_coercion.html">
|
||||
|
||||
<a href="parameter_coercion.html">
|
||||
|
||||
|
||||
Parameter coercion
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter active" data-level="1.4.4" 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=".." >Compiling 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="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>
|
||||
<h2 id="naive">Naive</h2>
|
||||
<ul>
|
||||
<li>Extracts the compiled route information on every request.</li>
|
||||
</ul>
|
||||
<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>
|
||||
[handler]
|
||||
(<span class="hljs-name"><span class="hljs-builtin-name">fn</span></span>
|
||||
([request]
|
||||
(<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)
|
||||
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">coerce-response</span> coercers request (<span class="hljs-name">handler</span> request)))
|
||||
(<span class="hljs-name">handler</span> request))))
|
||||
([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)
|
||||
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">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>
|
||||
<h2 id="compiled">Compiled</h2>
|
||||
<ul>
|
||||
<li>Route information is provided via a closure</li>
|
||||
<li>Pre-compiled coercers</li>
|
||||
<li>Mounts only if <code>:coercion</code> and <code>:responses</code> are defined for the route</li>
|
||||
</ul>
|
||||
<pre><code class="lang-clj">(<span class="hljs-name"><span class="hljs-builtin-name">def</span></span> gen-wrap-coerce-response
|
||||
<span class="hljs-string">"Generator for pluggable response coercion middleware.
|
||||
Expects a :coercion of type `reitit.coercion.protocol/Coercion`
|
||||
and :responses from route meta, otherwise does not mount."</span>
|
||||
(<span class="hljs-name">middleware/create</span>
|
||||
{<span class="hljs-symbol">:name</span> <span class="hljs-symbol">::coerce-response</span>
|
||||
<span class="hljs-symbol">:gen</span> (<span class="hljs-name"><span class="hljs-builtin-name">fn</span></span> [{<span class="hljs-symbol">:keys</span> [responses coercion opts]} _]
|
||||
(<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)]
|
||||
(<span class="hljs-name"><span class="hljs-builtin-name">fn</span></span> [handler]
|
||||
(<span class="hljs-name"><span class="hljs-builtin-name">fn</span></span>
|
||||
([request]
|
||||
(<span class="hljs-name">coerce-response</span> coercers request (<span class="hljs-name">handler</span> request)))
|
||||
([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>
|
||||
|
||||
|
||||
</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="parameter_coercion.html" class="navigation navigation-prev navigation-unique" aria-label="Previous page: Parameter coercion">
|
||||
<i class="fa fa-angle-left"></i>
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<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":""}});
|
||||
});
|
||||
</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>
|
||||
|
||||
525
ring/dynamic_extensions.html
Normal file
525
ring/dynamic_extensions.html
Normal file
|
|
@ -0,0 +1,525 @@
|
|||
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="" >
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
||||
<title>Dynamic extensions · 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="ring.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/different_routers.html">
|
||||
|
||||
<a href="../basics/different_routers.html">
|
||||
|
||||
|
||||
Different Routers
|
||||
|
||||
</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_conflicts.html">
|
||||
|
||||
<a href="../advanced/route_conflicts.html">
|
||||
|
||||
|
||||
Route conflicts
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.3.2" data-path="../advanced/route_validation.html">
|
||||
|
||||
<a href="../advanced/route_validation.html">
|
||||
|
||||
|
||||
Route Validation
|
||||
|
||||
</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 active" data-level="1.4.2" data-path="dynamic_extensions.html">
|
||||
|
||||
<a href="dynamic_extensions.html">
|
||||
|
||||
|
||||
Dynamic extensions
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.3" data-path="parameter_coercion.html">
|
||||
|
||||
<a href="parameter_coercion.html">
|
||||
|
||||
|
||||
Parameter coercion
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.4" 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=".." >Dynamic extensions</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="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>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-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>
|
||||
<p>Mounted to an app via router meta-data (effecting all routes):</p>
|
||||
<pre><code class="lang-clj">(<span class="hljs-name"><span class="hljs-builtin-name">def</span></span> handler (<span class="hljs-name"><span class="hljs-builtin-name">constantly</span></span> {<span class="hljs-symbol">:status</span> <span class="hljs-number">200</span>, <span class="hljs-symbol">:body</span> <span class="hljs-string">"ok"</span>}))
|
||||
|
||||
(<span class="hljs-name"><span class="hljs-builtin-name">def</span></span> app
|
||||
(<span class="hljs-name">ring/ring-handler</span>
|
||||
(<span class="hljs-name">ring/router</span>
|
||||
[[<span class="hljs-string">"/api"</span>
|
||||
[<span class="hljs-string">"/ping"</span> handler]
|
||||
[<span class="hljs-string">"/admin"</span> {<span class="hljs-symbol">::roles</span> #{<span class="hljs-symbol">:admin</span>}}
|
||||
[<span class="hljs-string">"/ping"</span> handler]]]]
|
||||
{<span class="hljs-symbol">:meta</span> {<span class="hljs-symbol">:middleware</span> [wrap-enforce-roles]}})))
|
||||
</code></pre>
|
||||
<p>Anonymous access to public route:</p>
|
||||
<pre><code class="lang-clj">(<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">"/api/ping"</span>})
|
||||
<span class="hljs-comment">; {:status 200, :body "ok"}</span>
|
||||
</code></pre>
|
||||
<p>Anonymous access to guarded route:</p>
|
||||
<pre><code class="lang-clj">(<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">"/api/admin/ping"</span>})
|
||||
<span class="hljs-comment">; {:status 403, :body "forbidden"}</span>
|
||||
</code></pre>
|
||||
<p>Authorized access to guarded route:</p>
|
||||
<pre><code class="lang-clj">(<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">"/api/admin/ping"</span>, <span class="hljs-symbol">::roles</span> #{<span class="hljs-symbol">:admin</span>}})
|
||||
<span class="hljs-comment">; {:status 200, :body "ok"}</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="ring.html" class="navigation navigation-prev " aria-label="Previous page: Ring-router">
|
||||
<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":"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":""}});
|
||||
});
|
||||
</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>
|
||||
|
||||
496
ring/index.html
Normal file
496
ring/index.html
Normal file
|
|
@ -0,0 +1,496 @@
|
|||
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="" >
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
||||
<title>Ring · 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="ring.html" />
|
||||
|
||||
|
||||
<link rel="prev" href="../advanced/configuring_routers.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/different_routers.html">
|
||||
|
||||
<a href="../basics/different_routers.html">
|
||||
|
||||
|
||||
Different Routers
|
||||
|
||||
</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_conflicts.html">
|
||||
|
||||
<a href="../advanced/route_conflicts.html">
|
||||
|
||||
|
||||
Route conflicts
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.3.2" data-path="../advanced/route_validation.html">
|
||||
|
||||
<a href="../advanced/route_validation.html">
|
||||
|
||||
|
||||
Route Validation
|
||||
|
||||
</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 active" 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 " data-level="1.4.3" data-path="parameter_coercion.html">
|
||||
|
||||
<a href="parameter_coercion.html">
|
||||
|
||||
|
||||
Parameter coercion
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.4" 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=".." >Ring</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="ring">Ring</h1>
|
||||
<ul>
|
||||
<li><a href="ring.html">Ring-router</a></li>
|
||||
<li><a href="dynamic_extensions.html">Dynamic extensions</a></li>
|
||||
<li><a href="parameter_coercion.html">Parameter coercion</a></li>
|
||||
<li><a href="compiling_middleware.html">Compiling middleware</a></li>
|
||||
</ul>
|
||||
|
||||
|
||||
</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="../advanced/configuring_routers.html" class="navigation navigation-prev " aria-label="Previous page: Configuring routers">
|
||||
<i class="fa fa-angle-left"></i>
|
||||
</a>
|
||||
|
||||
|
||||
<a href="ring.html" class="navigation navigation-next " aria-label="Next page: Ring-router">
|
||||
<i class="fa fa-angle-right"></i>
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<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":""}});
|
||||
});
|
||||
</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>
|
||||
|
||||
565
ring/parameter_coercion.html
Normal file
565
ring/parameter_coercion.html
Normal file
|
|
@ -0,0 +1,565 @@
|
|||
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="" >
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
||||
<title>Parameter coercion · 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="compiling_middleware.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/different_routers.html">
|
||||
|
||||
<a href="../basics/different_routers.html">
|
||||
|
||||
|
||||
Different Routers
|
||||
|
||||
</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_conflicts.html">
|
||||
|
||||
<a href="../advanced/route_conflicts.html">
|
||||
|
||||
|
||||
Route conflicts
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.3.2" data-path="../advanced/route_validation.html">
|
||||
|
||||
<a href="../advanced/route_validation.html">
|
||||
|
||||
|
||||
Route Validation
|
||||
|
||||
</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="parameter_coercion.html">
|
||||
|
||||
<a href="parameter_coercion.html">
|
||||
|
||||
|
||||
Parameter coercion
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.4" 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=".." >Parameter coercion</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="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><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>]
|
||||
[org.clojure/spec.alpha <span class="hljs-string">"0.1.123"</span>]
|
||||
[metosin/spec-tools <span class="hljs-string">"0.3.3"</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>
|
||||
<ol>
|
||||
<li>Define parameters and responses as data into route meta-data, in format adopted from <a href="https://github.com/metosin/ring-swagger#more-complete-example" target="_blank">ring-swagger</a>:<ul>
|
||||
<li><code>:parameters</code> map, with submaps for different parameters: <code>:query</code>, <code>:body</code>, <code>:form</code>, <code>:header</code> and <code>:path</code>. Parameters are defined in the format understood by the <code>Coercion</code>.</li>
|
||||
<li><code>:responses</code> map, with response status codes as keys (or <code>:default</code> for "everything else") with maps with <code>:schema</code> and optionally <code>:description</code> as values.</li>
|
||||
</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>
|
||||
</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"><span class="hljs-builtin-name">def</span></span> app
|
||||
(<span class="hljs-name">ring/ring-handler</span>
|
||||
(<span class="hljs-name">ring/router</span>
|
||||
[<span class="hljs-string">"/api"</span>
|
||||
[<span class="hljs-string">"/ping"</span> {<span class="hljs-symbol">:parameters</span> {<span class="hljs-symbol">:body</span> {<span class="hljs-symbol">:x</span> int?, <span class="hljs-symbol">:y</span> int?}}
|
||||
<span class="hljs-symbol">:responses</span> {<span class="hljs-number">200</span> {<span class="hljs-symbol">:schema</span> {<span class="hljs-symbol">:total</span> pos-int?}}}
|
||||
<span class="hljs-symbol">:get</span> {<span class="hljs-symbol">:handler</span> (<span class="hljs-name"><span class="hljs-builtin-name">fn</span></span> [{{{<span class="hljs-symbol">:keys</span> [x y]} <span class="hljs-symbol">:body</span>} <span class="hljs-symbol">:parameters</span>}]
|
||||
{<span class="hljs-symbol">:status</span> <span class="hljs-number">200</span>
|
||||
<span class="hljs-symbol">:body</span> {<span class="hljs-symbol">:total</span> (<span class="hljs-name"><span class="hljs-builtin-name">+</span></span> x y)}})}}]]
|
||||
{<span class="hljs-symbol">:meta</span> {<span class="hljs-symbol">:middleware</span> [coercion/gen-wrap-coerce-parameters
|
||||
coercion/gen-wrap-coerce-response]
|
||||
<span class="hljs-symbol">:coercion</span> spec/coercion}})))
|
||||
</code></pre>
|
||||
<pre><code class="lang-clj">(<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">"/api/ping"</span>
|
||||
<span class="hljs-symbol">:body-params</span> {<span class="hljs-symbol">:x</span> <span class="hljs-number">1</span>, <span class="hljs-symbol">:y</span> <span class="hljs-number">2</span>}})
|
||||
<span class="hljs-comment">; {:status 200, :body {:total 3}}</span>
|
||||
</code></pre>
|
||||
<h4 id="example-with-specs">Example with 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> '[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])
|
||||
|
||||
(<span class="hljs-name">s/def</span> <span class="hljs-symbol">::x</span> (<span class="hljs-name">st/spec</span> int?))
|
||||
(<span class="hljs-name">s/def</span> <span class="hljs-symbol">::y</span> (<span class="hljs-name">st/spec</span> int?))
|
||||
(<span class="hljs-name">s/def</span> <span class="hljs-symbol">::total</span> int?)
|
||||
(<span class="hljs-name">s/def</span> <span class="hljs-symbol">::request</span> (<span class="hljs-name">s/keys</span> <span class="hljs-symbol">:req-un</span> [<span class="hljs-symbol">::x</span> <span class="hljs-symbol">::y</span>]))
|
||||
(<span class="hljs-name">s/def</span> <span class="hljs-symbol">::response</span> (<span class="hljs-name">s/keys</span> <span class="hljs-symbol">:req-un</span> [<span class="hljs-symbol">::total</span>]))
|
||||
|
||||
(<span class="hljs-name"><span class="hljs-builtin-name">def</span></span> app
|
||||
(<span class="hljs-name">ring/ring-handler</span>
|
||||
(<span class="hljs-name">ring/router</span>
|
||||
[<span class="hljs-string">"/api"</span>
|
||||
[<span class="hljs-string">"/ping"</span> {<span class="hljs-symbol">:parameters</span> {<span class="hljs-symbol">:body</span> <span class="hljs-symbol">::request</span>}
|
||||
<span class="hljs-symbol">:responses</span> {<span class="hljs-number">200</span> {<span class="hljs-symbol">:schema</span> <span class="hljs-symbol">::response</span>}}
|
||||
<span class="hljs-symbol">:get</span> {<span class="hljs-symbol">:handler</span> (<span class="hljs-name"><span class="hljs-builtin-name">fn</span></span> [{{{<span class="hljs-symbol">:keys</span> [x y]} <span class="hljs-symbol">:body</span>} <span class="hljs-symbol">:parameters</span>}]
|
||||
{<span class="hljs-symbol">:status</span> <span class="hljs-number">200</span>
|
||||
<span class="hljs-symbol">:body</span> {<span class="hljs-symbol">:total</span> (<span class="hljs-name"><span class="hljs-builtin-name">+</span></span> x y)}})}}]]
|
||||
{<span class="hljs-symbol">:meta</span> {<span class="hljs-symbol">:middleware</span> [coercion/gen-wrap-coerce-parameters
|
||||
coercion/gen-wrap-coerce-response]
|
||||
<span class="hljs-symbol">:coercion</span> spec/coercion}})))
|
||||
</code></pre>
|
||||
<pre><code class="lang-clj">(<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">"/api/ping"</span>
|
||||
<span class="hljs-symbol">:body-params</span> {<span class="hljs-symbol">:x</span> <span class="hljs-number">1</span>, <span class="hljs-symbol">:y</span> <span class="hljs-number">2</span>}})
|
||||
<span class="hljs-comment">; {:status 200, :body {:total 3}}</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="dynamic_extensions.html" class="navigation navigation-prev " aria-label="Previous page: Dynamic extensions">
|
||||
<i class="fa fa-angle-left"></i>
|
||||
</a>
|
||||
|
||||
|
||||
<a href="compiling_middleware.html" class="navigation navigation-next " aria-label="Next page: Compiling middleware">
|
||||
<i class="fa fa-angle-right"></i>
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<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":""}});
|
||||
});
|
||||
</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>
|
||||
|
||||
574
ring/ring.html
Normal file
574
ring/ring.html
Normal file
|
|
@ -0,0 +1,574 @@
|
|||
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="" >
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
||||
<title>Ring-router · 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="dynamic_extensions.html" />
|
||||
|
||||
|
||||
<link rel="prev" href="./" />
|
||||
|
||||
|
||||
</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/different_routers.html">
|
||||
|
||||
<a href="../basics/different_routers.html">
|
||||
|
||||
|
||||
Different Routers
|
||||
|
||||
</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_conflicts.html">
|
||||
|
||||
<a href="../advanced/route_conflicts.html">
|
||||
|
||||
|
||||
Route conflicts
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.3.2" data-path="../advanced/route_validation.html">
|
||||
|
||||
<a href="../advanced/route_validation.html">
|
||||
|
||||
|
||||
Route Validation
|
||||
|
||||
</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 active" 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 " data-level="1.4.3" data-path="parameter_coercion.html">
|
||||
|
||||
<a href="parameter_coercion.html">
|
||||
|
||||
|
||||
Parameter coercion
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="1.4.4" 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=".." >Ring-router</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="ring-router">Ring Router</h1>
|
||||
<p><a href="https://github.com/ring-clojure/ring" target="_blank">Ring</a>-router adds support for <a href="https://github.com/ring-clojure/ring/wiki/Concepts#handlers" target="_blank">handlers</a>, <a href="https://github.com/ring-clojure/ring/wiki/Concepts#middleware" target="_blank">middleware</a> and routing based on <code>:request-method</code>. Ring-router is created with <code>reitit.ring/router</code> function. It runs a custom route compiler, creating a optimized stucture for handling route matches, with compiled middleware chain & handlers for all request methods. It also ensures that all routes have a <code>:handler</code> defined.</p>
|
||||
<p>Simple Ring app:</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"><span class="hljs-builtin-name">defn</span></span> handler [_]
|
||||
{<span class="hljs-symbol">:status</span> <span class="hljs-number">200</span>, <span class="hljs-symbol">:body</span> <span class="hljs-string">"ok"</span>})
|
||||
|
||||
(<span class="hljs-name"><span class="hljs-builtin-name">def</span></span> app
|
||||
(<span class="hljs-name">ring/ring-handler</span>
|
||||
(<span class="hljs-name">ring/router</span>
|
||||
[<span class="hljs-string">"/ping"</span> handler])))
|
||||
</code></pre>
|
||||
<p>Applying the handler:</p>
|
||||
<pre><code class="lang-clj">(<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">"/favicon.ico"</span>})
|
||||
<span class="hljs-comment">; nil</span>
|
||||
|
||||
(<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>
|
||||
<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>
|
||||
<span class="hljs-comment">; #Methods{:any #Endpoint{:meta {:handler #object[...]},</span>
|
||||
<span class="hljs-comment">; :handler #object[...],</span>
|
||||
<span class="hljs-comment">; :middleware []}}]]</span>
|
||||
</code></pre>
|
||||
<p>Note that the compiled resuts as third element in the route vector.</p>
|
||||
<h1 id="request-method-based-routing">Request-method based routing</h1>
|
||||
<p>Handler are also looked under request-method keys: <code>:get</code>, <code>:head</code>, <code>:patch</code>, <code>:delete</code>, <code>:options</code>, <code>:post</code> or <code>:put</code>. Top-level handler is used if request-method based handler is not found.</p>
|
||||
<pre><code class="lang-clj">(<span class="hljs-name"><span class="hljs-builtin-name">def</span></span> app
|
||||
(<span class="hljs-name">ring/ring-handler</span>
|
||||
(<span class="hljs-name">ring/router</span>
|
||||
[<span class="hljs-string">"/ping"</span> {<span class="hljs-symbol">:name</span> <span class="hljs-symbol">::ping</span>
|
||||
<span class="hljs-symbol">:get</span> handler
|
||||
<span class="hljs-symbol">:post</span> handler}])))
|
||||
|
||||
(<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>
|
||||
|
||||
(<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>
|
||||
<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>)
|
||||
<span class="hljs-symbol">:path</span>)
|
||||
<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>
|
||||
<ol>
|
||||
<li>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>
|
||||
<pre><code class="lang-clj">(<span class="hljs-name"><span class="hljs-builtin-name">defn</span></span> wrap [handler id]
|
||||
(<span class="hljs-name"><span class="hljs-builtin-name">fn</span></span> [request]
|
||||
(<span class="hljs-name">handler</span> (<span class="hljs-name">update</span> request <span class="hljs-symbol">::acc</span> (<span class="hljs-name">fnil</span> conj []) id))))
|
||||
|
||||
(<span class="hljs-name"><span class="hljs-builtin-name">defn</span></span> handler [{<span class="hljs-symbol">:keys</span> [<span class="hljs-symbol">::acc</span>]}]
|
||||
{<span class="hljs-symbol">:status</span> <span class="hljs-number">200</span>, <span class="hljs-symbol">:body</span> (<span class="hljs-name"><span class="hljs-builtin-name">conj</span></span> acc <span class="hljs-symbol">:handler</span>)})
|
||||
</code></pre>
|
||||
<p>App with nested middleware:</p>
|
||||
<pre><code class="lang-clj">(<span class="hljs-name"><span class="hljs-builtin-name">def</span></span> app
|
||||
(<span class="hljs-name">ring/ring-handler</span>
|
||||
(<span class="hljs-name">ring/router</span>
|
||||
[<span class="hljs-string">"/api"</span> {<span class="hljs-symbol">:middleware</span> [#(<span class="hljs-name">wrap</span> % <span class="hljs-symbol">:api</span>)]}
|
||||
[<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">:handler</span> handler}}]]])))
|
||||
</code></pre>
|
||||
<p>Middleware is applied correctly:</p>
|
||||
<pre><code class="lang-clj">(<span class="hljs-name">app</span> {<span class="hljs-symbol">:request-method</span> <span class="hljs-symbol">:delete</span>, <span class="hljs-symbol">:uri</span> <span class="hljs-string">"/api/ping"</span>})
|
||||
<span class="hljs-comment">; {:status 200, :body [:api :handler]}</span>
|
||||
</code></pre>
|
||||
<pre><code class="lang-clj">(<span class="hljs-name">app</span> {<span class="hljs-symbol">:request-method</span> <span class="hljs-symbol">:delete</span>, <span class="hljs-symbol">:uri</span> <span class="hljs-string">"/api/admin/db"</span>})
|
||||
<span class="hljs-comment">; {:status 200, :body [:api :admin :db :delete :handler]}</span>
|
||||
</code></pre>
|
||||
<h1 id="async-ring">Async Ring</h1>
|
||||
<p>All built-in middleware provide both 2 and 3-arity and are compiled for both Clojure & ClojureScript, so they work with <a href="https://www.booleanknot.com/blog/2016/07/15/asynchronous-ring.html" target="_blank">Async Ring</a> and <a href="https://nodejs.org" target="_blank">Node.js</a> too.</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="./" class="navigation navigation-prev " aria-label="Previous page: Ring">
|
||||
<i class="fa fa-angle-left"></i>
|
||||
</a>
|
||||
|
||||
|
||||
<a href="dynamic_extensions.html" class="navigation navigation-next " aria-label="Next page: Dynamic extensions">
|
||||
<i class="fa fa-angle-right"></i>
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<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":""}});
|
||||
});
|
||||
</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>
|
||||
|
||||
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue