/usr/share/doc/racket/web-server/dispatch.html is in racket-doc 6.7-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"/><title>5 URL-Based Dispatch</title><link rel="stylesheet" type="text/css" href="../scribble.css" title="default"/><link rel="stylesheet" type="text/css" href="../racket.css" title="default"/><link rel="stylesheet" type="text/css" href="../manual-style.css" title="default"/><link rel="stylesheet" type="text/css" href="../manual-racket.css" title="default"/><link rel="stylesheet" type="text/css" href="../doc-site.css" title="default"/><script type="text/javascript" src="../scribble-common.js"></script><script type="text/javascript" src="../manual-racket.js"></script><script type="text/javascript" src="../doc-site.js"></script><script type="text/javascript" src="../local-redirect/local-redirect.js"></script><script type="text/javascript" src="../local-redirect/local-user-redirect.js"></script><!--[if IE 6]><style type="text/css">.SIEHidden { overflow: hidden; }</style><![endif]--></head><body id="doc-racket-lang-org"><div class="tocset"><div class="tocview"><div class="tocviewlist tocviewlisttopspace"><div class="tocviewtitle"><table cellspacing="0" cellpadding="0"><tr><td style="width: 1em;"><a href="javascript:void(0);" title="Expand/Collapse" class="tocviewtoggle" onclick="TocviewToggle(this,"tocview_0");">▼</a></td><td></td><td><a href="index.html" class="tocviewlink" data-pltdoc="x">Web Applications in Racket</a></td></tr></table></div><div class="tocviewsublisttop" style="display: block;" id="tocview_0"><table cellspacing="0" cellpadding="0"><tr><td align="right">1 </td><td><a href="run.html" class="tocviewlink" data-pltdoc="x">Running Web Servlets</a></td></tr><tr><td align="right">2 </td><td><a href="servlet.html" class="tocviewlink" data-pltdoc="x">Stateful Servlets</a></td></tr><tr><td align="right">3 </td><td><a href="stateless.html" class="tocviewlink" data-pltdoc="x">Stateless Servlets</a></td></tr><tr><td align="right">4 </td><td><a href="http.html" class="tocviewlink" data-pltdoc="x">HTTP:<span class="mywbr"> </span> Hypertext Transfer Protocol</a></td></tr><tr><td align="right">5 </td><td><a href="" class="tocviewselflink" data-pltdoc="x">URL-<wbr></wbr>Based Dispatch</a></td></tr><tr><td align="right">6 </td><td><a href="formlets.html" class="tocviewlink" data-pltdoc="x">Formlets:<span class="mywbr"> </span> Functional Form Abstraction</a></td></tr><tr><td align="right">7 </td><td><a href="templates.html" class="tocviewlink" data-pltdoc="x">Templates:<span class="mywbr"> </span> Separation of View</a></td></tr><tr><td align="right">8 </td><td><a href="page.html" class="tocviewlink" data-pltdoc="x">Page:<span class="mywbr"> </span> Short-<wbr></wbr>hand for Common Patterns</a></td></tr><tr><td align="right">9 </td><td><a href="test.html" class="tocviewlink" data-pltdoc="x">Testing Servlets</a></td></tr><tr><td align="right">10 </td><td><a href="faq.html" class="tocviewlink" data-pltdoc="x">Troubleshooting and Tips</a></td></tr><tr><td align="right"></td><td><a href="doc-index.html" class="tocviewlink" data-pltdoc="x">Index</a></td></tr></table></div></div><div class="tocviewlist"><table cellspacing="0" cellpadding="0"><tr><td style="width: 1em;"><a href="javascript:void(0);" title="Expand/Collapse" class="tocviewtoggle" onclick="TocviewToggle(this,"tocview_1");">►</a></td><td>5 </td><td><a href="" class="tocviewselflink" data-pltdoc="x">URL-<wbr></wbr>Based Dispatch</a></td></tr></table><div class="tocviewsublistbottom" style="display: none;" id="tocview_1"><table cellspacing="0" cellpadding="0"><tr><td align="right">5.1 </td><td><a href="#%28part._.Using_web-server_dispatch%29" class="tocviewlink" data-pltdoc="x">Using <span class="RktModLink"><span class="RktSym">web-<wbr></wbr>server/<span class="mywbr"> </span>dispatch</span></span></a></td></tr><tr><td align="right">5.2 </td><td><a href="#%28part._.A.P.I_.Reference%29" class="tocviewlink" data-pltdoc="x">API Reference</a></td></tr><tr><td align="right">5.3 </td><td><a href="#%28part._.Imperative_.Dispatch_.Containers%29" class="tocviewlink" data-pltdoc="x">Imperative Dispatch Containers</a></td></tr><tr><td align="right">5.4 </td><td><a href="#%28part._.Built-in_.U.R.L_patterns%29" class="tocviewlink" data-pltdoc="x">Built-<wbr></wbr>in URL patterns</a></td></tr><tr><td align="right">5.5 </td><td><a href="#%28part._.Extending_web-server_dispatch%29" class="tocviewlink" data-pltdoc="x">Extending <span class="RktModLink"><span class="RktSym">web-<wbr></wbr>server/<span class="mywbr"> </span>dispatch</span></span></a></td></tr></table></div></div></div><div class="tocsub"><div class="tocsubtitle">On this page:</div><table class="tocsublist" cellspacing="0"><tr><td><span class="tocsublinknumber">5.1<tt> </tt></span><a href="#%28part._.Using_web-server_dispatch%29" class="tocsubseclink" data-pltdoc="x">Using <span class="RktModLink"><span class="RktSym">web-<wbr></wbr>server/<span class="mywbr"> </span>dispatch</span></span></a></td></tr><tr><td><span class="tocsublinknumber">5.2<tt> </tt></span><a href="#%28part._.A.P.I_.Reference%29" class="tocsubseclink" data-pltdoc="x">API Reference</a></td></tr><tr><td><a href="#%28form._%28%28lib._web-server%2Fdispatch..rkt%29._dispatch-rules%29%29" class="tocsubnonseclink" data-pltdoc="x"><span class="RktSym"><span class="RktStxLink">dispatch-<wbr></wbr>rules</span></span></a></td></tr><tr><td><a href="#%28form._%28%28lib._web-server%2Fdispatch..rkt%29._dispatch-rules%2Bapplies%29%29" class="tocsubnonseclink" data-pltdoc="x"><span class="RktSym"><span class="RktStxLink">dispatch-<wbr></wbr>rules+<span class="mywbr"> </span>applies</span></span></a></td></tr><tr><td><a href="#%28form._%28%28lib._web-server%2Fdispatch..rkt%29._dispatch-case%29%29" class="tocsubnonseclink" data-pltdoc="x"><span class="RktSym"><span class="RktStxLink">dispatch-<wbr></wbr>case</span></span></a></td></tr><tr><td><a href="#%28form._%28%28lib._web-server%2Fdispatch..rkt%29._dispatch-url%29%29" class="tocsubnonseclink" data-pltdoc="x"><span class="RktSym"><span class="RktStxLink">dispatch-<wbr></wbr>url</span></span></a></td></tr><tr><td><a href="#%28def._%28%28lib._web-server%2Fdispatch..rkt%29._serve%2Fdispatch%29%29" class="tocsubnonseclink" data-pltdoc="x"><span class="RktSym"><span class="RktValLink">serve/<span class="mywbr"> </span>dispatch</span></span></a></td></tr><tr><td><span class="tocsublinknumber">5.3<tt> </tt></span><a href="#%28part._.Imperative_.Dispatch_.Containers%29" class="tocsubseclink" data-pltdoc="x">Imperative Dispatch Containers</a></td></tr><tr><td><a href="#%28def._%28%28lib._web-server%2Fdispatch..rkt%29._container~3f%29%29" class="tocsubnonseclink" data-pltdoc="x"><span class="RktSym"><span class="RktValLink">container?</span></span></a></td></tr><tr><td><a href="#%28form._%28%28lib._web-server%2Fdispatch..rkt%29._define-container%29%29" class="tocsubnonseclink" data-pltdoc="x"><span class="RktSym"><span class="RktStxLink">define-<wbr></wbr>container</span></span></a></td></tr><tr><td><a href="#%28form._%28%28lib._web-server%2Fdispatch..rkt%29._dispatch-rules%21%29%29" class="tocsubnonseclink" data-pltdoc="x"><span class="RktSym"><span class="RktStxLink">dispatch-<wbr></wbr>rules!</span></span></a></td></tr><tr><td><span class="tocsublinknumber">5.4<tt> </tt></span><a href="#%28part._.Built-in_.U.R.L_patterns%29" class="tocsubseclink" data-pltdoc="x">Built-<wbr></wbr>in URL patterns</a></td></tr><tr><td><a href="#%28form._%28%28lib._web-server%2Fdispatch..rkt%29._number-arg%29%29" class="tocsubnonseclink" data-pltdoc="x"><span class="RktSym"><span class="RktStxLink">number-<wbr></wbr>arg</span></span></a></td></tr><tr><td><a href="#%28form._%28%28lib._web-server%2Fdispatch..rkt%29._integer-arg%29%29" class="tocsubnonseclink" data-pltdoc="x"><span class="RktSym"><span class="RktStxLink">integer-<wbr></wbr>arg</span></span></a></td></tr><tr><td><a href="#%28form._%28%28lib._web-server%2Fdispatch..rkt%29._real-arg%29%29" class="tocsubnonseclink" data-pltdoc="x"><span class="RktSym"><span class="RktStxLink">real-<wbr></wbr>arg</span></span></a></td></tr><tr><td><a href="#%28form._%28%28lib._web-server%2Fdispatch..rkt%29._string-arg%29%29" class="tocsubnonseclink" data-pltdoc="x"><span class="RktSym"><span class="RktStxLink">string-<wbr></wbr>arg</span></span></a></td></tr><tr><td><a href="#%28form._%28%28lib._web-server%2Fdispatch..rkt%29._symbol-arg%29%29" class="tocsubnonseclink" data-pltdoc="x"><span class="RktSym"><span class="RktStxLink">symbol-<wbr></wbr>arg</span></span></a></td></tr><tr><td><span class="tocsublinknumber">5.5<tt> </tt></span><a href="#%28part._.Extending_web-server_dispatch%29" class="tocsubseclink" data-pltdoc="x">Extending <span class="RktModLink"><span class="RktSym">web-<wbr></wbr>server/<span class="mywbr"> </span>dispatch</span></span></a></td></tr><tr><td><a href="#%28form._%28%28lib._web-server%2Fdispatch%2Fextend..rkt%29._define-bidi-match-expander%29%29" class="tocsubnonseclink" data-pltdoc="x"><span class="RktSym"><span class="RktStxLink">define-<wbr></wbr>bidi-<wbr></wbr>match-<wbr></wbr>expander</span></span></a></td></tr><tr><td><a href="#%28form._%28%28lib._web-server%2Fdispatch%2Fextend..rkt%29._bidi-match-going-in~3f%29%29" class="tocsubnonseclink" data-pltdoc="x"><span class="RktSym"><span class="RktStxLink">bidi-<wbr></wbr>match-<wbr></wbr>going-<wbr></wbr>in?</span></span></a></td></tr><tr><td><a href="#%28form._%28%28lib._web-server%2Fdispatch%2Fextend..rkt%29._define-coercion-match-expander%29%29" class="tocsubnonseclink" data-pltdoc="x"><span class="RktSym"><span class="RktStxLink">define-<wbr></wbr>coercion-<wbr></wbr>match-<wbr></wbr>expander</span></span></a></td></tr><tr><td><a href="#%28def._%28%28lib._web-server%2Fdispatch%2Fextend..rkt%29._make-coerce-safe~3f%29%29" class="tocsubnonseclink" data-pltdoc="x"><span class="RktSym"><span class="RktValLink">make-<wbr></wbr>coerce-<wbr></wbr>safe?</span></span></a></td></tr></table></div></div><div class="maincolumn"><div class="main"><div class="navsettop"><span class="navleft"><form class="searchform"><input class="searchbox" style="color: #888;" type="text" value="...search manuals..." title="Enter a search string to search the manuals" onkeypress="return DoSearchKey(event, this, "6.7", "../");" onfocus="this.style.color="black"; this.style.textAlign="left"; if (this.value == "...search manuals...") this.value="";" onblur="if (this.value.match(/^ *$/)) { this.style.color="#888"; this.style.textAlign="center"; this.value="...search manuals..."; }"/></form> <a href="../index.html" title="up to the documentation top" data-pltdoc="x" onclick="return GotoPLTRoot("6.7");">top</a></span><span class="navright"> <a href="http.html" title="backward to "4 HTTP: Hypertext Transfer Protocol"" data-pltdoc="x">← prev</a> <a href="index.html" title="up to "Web Applications in Racket"" data-pltdoc="x">up</a> <a href="formlets.html" title="forward to "6 Formlets: Functional Form Abstraction"" data-pltdoc="x">next →</a></span> </div><h3 x-source-module="(lib "web-server/scribblings/web-server.scrbl")" x-source-pkg="web-server-doc" x-part-tag=""dispatch"">5<tt> </tt><a name="(part._dispatch)"></a><a name="(mod-path._web-server/dispatch)"></a>URL-Based Dispatch</h3><p><table cellspacing="0" cellpadding="0" class="defmodule"><tr><td align="left"><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=require.html%23%2528form._%2528%2528lib._racket%252Fprivate%252Fbase..rkt%2529._require%2529%2529&version=6.7" class="RktStxLink Sq" data-pltdoc="x">require</a></span><span class="stt"> </span><a href="" class="RktModLink" data-pltdoc="x"><span class="RktSym">web-server/dispatch</span></a><span class="RktPn">)</span></td><td align="right"><span class="RpackageSpec"><span class="Smaller"> package:</span> <span class="stt">web-server-lib</span></span></td></tr></table></p><p>The library allows the creation of two-way mappings between permanent URLs and request-handling procedures.</p><blockquote class="refpara"><blockquote class="refcolumn"><blockquote class="refcontent"><p>This library was inspired by the <span class="RktPn">(</span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=require.html%23%2528form._%2528%2528lib._racket%252Fprivate%252Fbase..rkt%2529._planet%2529%2529&version=6.7" class="RktStxLink Sq" data-pltdoc="x">planet</a></span><span class="stt"> </span><span class="RktSym">untyped/dispatch</span><span class="RktPn">)</span> package.</p></blockquote></blockquote></blockquote><h4 x-source-module="(lib "web-server/scribblings/web-server.scrbl")" x-source-pkg="web-server-doc" x-part-tag=""Using_web-server_dispatch"">5.1<tt> </tt><a name="(part._.Using_web-server_dispatch)"></a>Using <a href="" class="RktModLink" data-pltdoc="x"><span class="RktSym">web-server/dispatch</span></a></h4><p>Suppose you are writing a blog application and want pretty URLs for different views of the site.
You would define some URL dispatching rules as follows:</p><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="stt">> </span><span class="RktPn">(</span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=define.html%23%2528form._%2528%2528quote._%7E23%7E25kernel%2529._define-values%2529%2529&version=6.7" class="RktStxLink Sq" data-pltdoc="x">define-values</a></span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym">blog-dispatch</span><span class="hspace"> </span><span class="RktSym">blog-url</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="#%28form._%28%28lib._web-server%2Fdispatch..rkt%29._dispatch-rules%29%29" class="RktStxLink" data-pltdoc="x">dispatch-rules</a></span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktVal">""</span><span class="RktPn">)</span><span class="hspace"> </span><span class="RktSym">list-posts</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktVal">"posts"</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="#%28form._%28%28lib._web-server%2Fdispatch..rkt%29._string-arg%29%29" class="RktStxLink" data-pltdoc="x">string-arg</a></span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace"> </span><span class="RktSym">review-post</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktVal">"archive"</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="#%28form._%28%28lib._web-server%2Fdispatch..rkt%29._integer-arg%29%29" class="RktStxLink" data-pltdoc="x">integer-arg</a></span><span class="RktPn">)</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="#%28form._%28%28lib._web-server%2Fdispatch..rkt%29._integer-arg%29%29" class="RktStxLink" data-pltdoc="x">integer-arg</a></span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace"> </span><span class="RktSym">review-archive</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktPn">[</span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=if.html%23%2528form._%2528%2528lib._racket%252Fprivate%252Fletstx-scheme..rkt%2529._else%2529%2529&version=6.7" class="RktStxLink Sq" data-pltdoc="x">else</a></span><span class="hspace"> </span><span class="RktSym">list-posts</span><span class="RktPn">]</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></td></tr></table></blockquote><p><div class="SIntrapara">And define your request handlers as follows:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="stt">> </span><span class="RktPn">(</span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=define.html%23%2528form._%2528%2528lib._racket%252Fprivate%252Fbase..rkt%2529._define%2529%2529&version=6.7" class="RktStxLink Sq" data-pltdoc="x">define</a></span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym">list-posts</span><span class="hspace"> </span><span class="RktSym">req</span><span class="RktPn">)</span><span class="hspace"> </span><span class="RktVal">`</span><span class="RktVal">(</span><span class="RktVal">list-posts</span><span class="RktVal">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="stt">> </span><span class="RktPn">(</span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=define.html%23%2528form._%2528%2528lib._racket%252Fprivate%252Fbase..rkt%2529._define%2529%2529&version=6.7" class="RktStxLink Sq" data-pltdoc="x">define</a></span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym">review-post</span><span class="hspace"> </span><span class="RktSym">req</span><span class="hspace"> </span><span class="RktSym">p</span><span class="RktPn">)</span><span class="hspace"> </span><span class="RktVal">`</span><span class="RktVal">(</span><span class="RktVal">review-post</span><span class="hspace"> </span><span class="RktRdr">,</span><span class="RktSym">p</span><span class="RktVal">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="stt">> </span><span class="RktPn">(</span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=define.html%23%2528form._%2528%2528lib._racket%252Fprivate%252Fbase..rkt%2529._define%2529%2529&version=6.7" class="RktStxLink Sq" data-pltdoc="x">define</a></span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym">review-archive</span><span class="hspace"> </span><span class="RktSym">req</span><span class="hspace"> </span><span class="RktSym">y</span><span class="hspace"> </span><span class="RktSym">m</span><span class="RktPn">)</span><span class="hspace"> </span><span class="RktVal">`</span><span class="RktVal">(</span><span class="RktVal">review-archive</span><span class="hspace"> </span><span class="RktRdr">,</span><span class="RktSym">y</span><span class="hspace"> </span><span class="RktRdr">,</span><span class="RktSym">m</span><span class="RktVal">)</span><span class="RktPn">)</span></td></tr></table></blockquote></div></p><p><div class="SIntrapara">Now when a request is sent to your application, it will be directed to the appropriate handler:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="stt">> </span><span class="RktPn">(</span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=define.html%23%2528form._%2528%2528lib._racket%252Fprivate%252Fbase..rkt%2529._define%2529%2529&version=6.7" class="RktStxLink Sq" data-pltdoc="x">define</a></span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym">url->request</span><span class="hspace"> </span><span class="RktSym">u</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="http.html#%28def._%28%28lib._web-server%2Fhttp%2Frequest-structs..rkt%29._make-request%29%29" class="RktValLink" data-pltdoc="x">make-request</a></span><span class="hspace"> </span><span class="RktVal">#"GET"</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=net&rel=url.html%23%2528def._%2528%2528lib._net%252Furl..rkt%2529._string-%7E3eurl%2529%2529&version=6.7" class="RktValLink Sq" data-pltdoc="x">string->url</a></span><span class="hspace"> </span><span class="RktSym">u</span><span class="RktPn">)</span><span class="hspace"> </span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=pairs.html%23%2528def._%2528%2528lib._racket%252Flist..rkt%2529._empty%2529%2529&version=6.7" class="RktValLink Sq" data-pltdoc="x">empty</a></span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym">delay</span><span class="hspace"> </span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=pairs.html%23%2528def._%2528%2528lib._racket%252Flist..rkt%2529._empty%2529%2529&version=6.7" class="RktValLink Sq" data-pltdoc="x">empty</a></span><span class="RktPn">)</span><span class="hspace"> </span><span class="RktVal">#f</span><span class="hspace"> </span><span class="RktVal">"1.2.3.4"</span><span class="hspace"> </span><span class="RktVal">80</span><span class="hspace"> </span><span class="RktVal">"4.3.2.1"</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></td></tr><tr><td><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="stt">> </span><span class="RktPn">(</span><span class="RktSym">blog-dispatch</span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym">url->request</span><span class="hspace"> </span><span class="RktVal">"http://www.chrlsnchrg.com"</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></td></tr><tr><td><p><span class="RktRes">'(list-posts)</span></p></td></tr><tr><td><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="stt">> </span><span class="RktPn">(</span><span class="RktSym">blog-dispatch</span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym">url->request</span><span class="hspace"> </span><span class="RktVal">"http://www.chrlsnchrg.com/"</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></td></tr><tr><td><p><span class="RktRes">'(list-posts)</span></p></td></tr><tr><td><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="stt">> </span><span class="RktPn">(</span><span class="RktSym">blog-dispatch</span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym">url->request</span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktVal">"http://www.chrlsnchrg.com/posts/Extracurricular-Activity"</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></td></tr><tr><td><p><span class="RktRes">'(review-post "Extracurricular-Activity")</span></p></td></tr><tr><td><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="stt">> </span><span class="RktPn">(</span><span class="RktSym">blog-dispatch</span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym">url->request</span><span class="hspace"> </span><span class="RktVal">"http://www.chrlsnchrg.com/archive/1984/10"</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></td></tr><tr><td><p><span class="RktRes">'(review-archive 1984 10)</span></p></td></tr><tr><td><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="stt">> </span><span class="RktPn">(</span><span class="RktSym">blog-dispatch</span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym">url->request</span><span class="hspace"> </span><span class="RktVal">"http://www.chrlsnchrg.com/contact"</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></td></tr><tr><td><p><span class="RktRes">'(list-posts)</span></p></td></tr></table></blockquote></div></p><p><div class="SIntrapara">You can also generate these pretty URLs from procedure calls:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="stt">> </span><span class="RktPn">(</span><span class="RktSym">blog-url</span><span class="hspace"> </span><span class="RktSym">list-posts</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">"/"</span></p></td></tr><tr><td><span class="stt">> </span><span class="RktPn">(</span><span class="RktSym">blog-url</span><span class="hspace"> </span><span class="RktSym">review-post</span><span class="hspace"> </span><span class="RktVal">"Another-Saturday-Night"</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">"/posts/Another-Saturday-Night"</span></p></td></tr><tr><td><span class="stt">> </span><span class="RktPn">(</span><span class="RktSym">blog-url</span><span class="hspace"> </span><span class="RktSym">review-archive</span><span class="hspace"> </span><span class="RktVal">1984</span><span class="hspace"> </span><span class="RktVal">11</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">"/archive/1984/11"</span></p></td></tr></table></blockquote></div></p><p><div class="SIntrapara">After mastering the world of blogging software, you decide to put the ubiquitous Add-Two-Numbers.com out of business with Sum.com:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="stt">> </span><span class="RktPn">(</span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=define.html%23%2528form._%2528%2528quote._%7E23%7E25kernel%2529._define-values%2529%2529&version=6.7" class="RktStxLink Sq" data-pltdoc="x">define-values</a></span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym">sum-dispatch</span><span class="hspace"> </span><span class="RktSym">sum-url</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="#%28form._%28%28lib._web-server%2Fdispatch..rkt%29._dispatch-rules%29%29" class="RktStxLink" data-pltdoc="x">dispatch-rules</a></span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym"><a href="#%28form._%28%28lib._web-server%2Fdispatch..rkt%29._integer-arg%29%29" class="RktStxLink" data-pltdoc="x">integer-arg</a></span><span class="RktPn">)</span><span class="hspace"> </span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=stx-patterns.html%23%2528form._%2528%2528lib._racket%252Fprivate%252Fstxcase-scheme..rkt%2529._......%2529%2529&version=6.7" class="RktStxLink Sq" data-pltdoc="x">...</a></span><span class="RktPn">)</span><span class="hspace"> </span><span class="RktSym">sum</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktPn">[</span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=if.html%23%2528form._%2528%2528lib._racket%252Fprivate%252Fletstx-scheme..rkt%2529._else%2529%2529&version=6.7" class="RktStxLink Sq" data-pltdoc="x">else</a></span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=lambda.html%23%2528form._%2528%2528lib._racket%252Fprivate%252Fbase..rkt%2529._lambda%2529%2529&version=6.7" class="RktStxLink Sq" data-pltdoc="x">lambda</a></span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym">req</span><span class="RktPn">)</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym">sum</span><span class="hspace"> </span><span class="RktSym">req</span><span class="hspace"> </span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=pairs.html%23%2528def._%2528%2528lib._racket%252Flist..rkt%2529._empty%2529%2529&version=6.7" class="RktValLink Sq" data-pltdoc="x">empty</a></span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></td></tr><tr><td><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="stt">> </span><span class="RktPn">(</span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=define.html%23%2528form._%2528%2528lib._racket%252Fprivate%252Fbase..rkt%2529._define%2529%2529&version=6.7" class="RktStxLink Sq" data-pltdoc="x">define</a></span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym">sum</span><span class="hspace"> </span><span class="RktSym">req</span><span class="hspace"> </span><span class="RktSym">is</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=procedures.html%23%2528def._%2528%2528lib._racket%252Fprivate%252Fbase..rkt%2529._apply%2529%2529&version=6.7" class="RktValLink Sq" data-pltdoc="x">apply</a></span><span class="hspace"> </span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=generic-numbers.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._%252B%2529%2529&version=6.7" class="RktValLink Sq" data-pltdoc="x">+</a></span><span class="hspace"> </span><span class="RktSym">is</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></td></tr><tr><td><span class="stt">> </span><span class="RktPn">(</span><span class="RktSym">sum-dispatch</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym">url->request</span><span class="hspace"> </span><span class="RktVal">"http://www.sum.com/"</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">0</span></p></td></tr><tr><td><span class="stt">> </span><span class="RktPn">(</span><span class="RktSym">sum-dispatch</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym">url->request</span><span class="hspace"> </span><span class="RktVal">"http://www.sum.com/2"</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">2</span></p></td></tr><tr><td><span class="stt">> </span><span class="RktPn">(</span><span class="RktSym">sum-dispatch</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym">url->request</span><span class="hspace"> </span><span class="RktVal">"http://www.sum.com/2/3/4"</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">9</span></p></td></tr><tr><td><span class="stt">> </span><span class="RktPn">(</span><span class="RktSym">sum-dispatch</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym">url->request</span><span class="hspace"> </span><span class="RktVal">"http://www.sum.com/5/10/15/20"</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">50</span></p></td></tr><tr><td><span class="stt">> </span><span class="RktPn">(</span><span class="RktSym">sum-url</span><span class="hspace"> </span><span class="RktSym">sum</span><span class="hspace"> </span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=pairs.html%23%2528def._%2528%2528lib._racket%252Flist..rkt%2529._empty%2529%2529&version=6.7" class="RktValLink Sq" data-pltdoc="x">empty</a></span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">"/"</span></p></td></tr><tr><td><span class="stt">> </span><span class="RktPn">(</span><span class="RktSym">sum-url</span><span class="hspace"> </span><span class="RktSym">sum</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=pairs.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._list%2529%2529&version=6.7" class="RktValLink Sq" data-pltdoc="x">list</a></span><span class="hspace"> </span><span class="RktVal">1</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">"/1"</span></p></td></tr><tr><td><span class="stt">> </span><span class="RktPn">(</span><span class="RktSym">sum-url</span><span class="hspace"> </span><span class="RktSym">sum</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=pairs.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._list%2529%2529&version=6.7" class="RktValLink Sq" data-pltdoc="x">list</a></span><span class="hspace"> </span><span class="RktVal">2</span><span class="hspace"> </span><span class="RktVal">3</span><span class="hspace"> </span><span class="RktVal">5</span><span class="hspace"> </span><span class="RktVal">7</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">"/2/3/5/7"</span></p></td></tr></table></blockquote></div></p><p>When you use <a href="" class="RktModLink" data-pltdoc="x"><span class="RktSym">web-server/dispatch</span></a> with
<span class="RktSym"><a href="run.html#%28def._%28%28lib._web-server%2Fservlet-env..rkt%29._serve%2Fservlet%29%29" class="RktValLink" data-pltdoc="x">serve/servlet</a></span>, you almost always want to use the
<span class="RktPn">#:servlet-regexp</span> argument with the value <span class="RktVal">""</span> to
capture all top-level requests. However, make sure you don’t include
an <span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=if.html%23%2528form._%2528%2528lib._racket%252Fprivate%252Fletstx-scheme..rkt%2529._else%2529%2529&version=6.7" class="RktStxLink Sq" data-pltdoc="x">else</a></span> in your rules if you are also serving static files,
or else the filesystem server will never see the requests.</p><h4 x-source-module="(lib "web-server/scribblings/web-server.scrbl")" x-source-pkg="web-server-doc" x-part-tag=""API_Reference"">5.2<tt> </tt><a name="(part._.A.P.I_.Reference)"></a>API Reference</h4><p><div class="SIntrapara"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><blockquote class="SubFlow"><div class="RBackgroundLabel SIEHidden"><div class="RBackgroundLabelInner"><p>syntax</p></div></div><table cellspacing="0" cellpadding="0" class="RktBlk RForeground"><tr><td><span class="RktPn">(</span><a name="(form._((lib._web-server/dispatch..rkt)._dispatch-rules))"></a><span title="Provided from: web-server/dispatch | Package: web-server-lib"><span class="RktSym"><a href="#%28form._%28%28lib._web-server%2Fdispatch..rkt%29._dispatch-rules%29%29" class="RktStxDef RktStxLink" data-pltdoc="x">dispatch-rules</a></span></span></td></tr><tr><td><span class="hspace"> </span><span class="RktVar">dispatch-clause</span><span class="hspace"> </span><span class="RktMeta">...</span></td></tr><tr><td><span class="hspace"> </span><span class="RktVar">maybe-else-clause</span><span class="RktPn">)</span></td></tr></table></blockquote></td></tr><tr><td><span class="stt"> </span></td></tr><tr><td><table cellspacing="0" cellpadding="0" class="specgrammar"><tr><td align="right" valign="baseline"><span class="RktVar">dispatch-clause</span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="center" valign="baseline">=</td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="RktPn">[</span><span class="RktVar">dispatch-pattern</span><span class="hspace"> </span><span class="RktVar">maybe-method</span><span class="hspace"> </span><span class="RktVar">dispatch-fun</span><span class="RktPn">]</span></td></tr><tr><td align="right" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="center" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td></tr><tr><td align="right" valign="baseline"><span class="RktVar">dispatch-pattern</span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="center" valign="baseline">=</td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="RktPn">(</span><span class="RktPn">)</span></td></tr><tr><td align="right" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="center" valign="baseline">|</td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="RktPn">(</span><span class="RktVar">string</span><span class="hspace"> </span><span class="RktPn">. </span><span class="RktVar">dispatch-pattern</span><span class="RktPn">)</span></td></tr><tr><td align="right" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="center" valign="baseline">|</td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="RktPn">(</span><span class="RktVar">bidi-match-expander</span><span class="hspace"> </span><span class="RktMeta">...</span><span class="hspace"> </span><span class="RktPn">. </span><span class="RktVar">dispatch-pattern</span><span class="RktPn">)</span></td></tr><tr><td align="right" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="center" valign="baseline">|</td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="RktPn">(</span><span class="RktVar">bidi-match-expander</span><span class="hspace"> </span><span class="RktPn">. </span><span class="RktVar">dispatch-pattern</span><span class="RktPn">)</span></td></tr><tr><td align="right" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="center" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td></tr><tr><td align="right" valign="baseline"><span class="RktVar">maybe-method</span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="center" valign="baseline">=</td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td></td></tr></table></td></tr><tr><td align="right" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="center" valign="baseline">|</td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="RktPn">#:method</span><span class="hspace"> </span><span class="RktVar">method</span></td></tr><tr><td align="right" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="center" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td></tr><tr><td align="right" valign="baseline"><span class="RktVar">method</span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="center" valign="baseline">=</td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="RktVar">pat</span></td></tr><tr><td align="right" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="center" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td></tr><tr><td align="right" valign="baseline"><span class="RktVar">maybe-else-clause</span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="center" valign="baseline">=</td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td></td></tr></table></td></tr><tr><td align="right" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="center" valign="baseline">|</td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="RktPn">[</span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=if.html%23%2528form._%2528%2528lib._racket%252Fprivate%252Fletstx-scheme..rkt%2529._else%2529%2529&version=6.7" class="RktStxLink Sq" data-pltdoc="x">else</a></span><span class="hspace"> </span><span class="RktVar">else-fun</span><span class="RktPn">]</span></td></tr></table></td></tr><tr><td><span class="stt"> </span></td></tr><tr><td><blockquote class="SubFlow"><table cellspacing="0" cellpadding="0" class="argcontract"><tr><td><span class="hspace"> </span></td><td><span class="RktVar">else-fun</span></td><td><span class="hspace"> </span></td><td>:</td><td><span class="hspace"> </span></td><td><span class="RktPn">(</span><span class="RktSym"><a href="http.html#%28def._%28%28lib._web-server%2Fhttp%2Frequest-structs..rkt%29._request~3f%29%29" class="RktValLink" data-pltdoc="x">request?</a></span><span class="hspace"> </span><span class="RktPn">. </span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=function-contracts.html%23%2528form._%2528%2528lib._racket%252Fcontract%252Fbase..rkt%2529._-%7E3e%2529%2529&version=6.7" class="RktStxLink Sq" data-pltdoc="x"><span class="nobreak">-></span></a></span><span class="RktPn"> .</span><span class="hspace"> </span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=data-structure-contracts.html%23%2528form._%2528%2528lib._racket%252Fcontract%252Fprivate%252Fmisc..rkt%2529._any%2529%2529&version=6.7" class="RktStxLink Sq" data-pltdoc="x">any</a></span><span class="RktPn">)</span></td></tr></table><table cellspacing="0" cellpadding="0" class="argcontract"><tr><td><span class="hspace"> </span></td><td><span class="RktVar">dispatch-fun</span></td><td><span class="hspace"> </span></td><td>:</td><td><span class="hspace"> </span></td><td><span class="RktPn">(</span><span class="RktSym"><a href="http.html#%28def._%28%28lib._web-server%2Fhttp%2Frequest-structs..rkt%29._request~3f%29%29" class="RktValLink" data-pltdoc="x">request?</a></span><span class="hspace"> </span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=data-structure-contracts.html%23%2528def._%2528%2528lib._racket%252Fcontract%252Fprivate%252Fmisc..rkt%2529._any%252Fc%2529%2529&version=6.7" class="RktValLink Sq" data-pltdoc="x">any/c</a></span><span class="hspace"> </span><span class="RktMeta"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=stx-patterns.html%23%2528form._%2528%2528lib._racket%252Fprivate%252Fstxcase-scheme..rkt%2529._......%2529%2529&version=6.7" class="RktStxLink Sq" data-pltdoc="x">...</a></span><span class="hspace"> </span><span class="RktPn">. </span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=function-contracts.html%23%2528form._%2528%2528lib._racket%252Fcontract%252Fbase..rkt%2529._-%7E3e%2529%2529&version=6.7" class="RktStxLink Sq" data-pltdoc="x"><span class="nobreak">-></span></a></span><span class="RktPn"> .</span><span class="hspace"> </span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=data-structure-contracts.html%23%2528form._%2528%2528lib._racket%252Fcontract%252Fprivate%252Fmisc..rkt%2529._any%2529%2529&version=6.7" class="RktStxLink Sq" data-pltdoc="x">any</a></span><span class="RktPn">)</span></td></tr></table></blockquote></td></tr></table></blockquote></div><div class="SIntrapara">Returns two values: the first is a dispatching function with the
contract <span class="RktPn">(</span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=function-contracts.html%23%2528form._%2528%2528lib._racket%252Fcontract%252Fbase..rkt%2529._-%7E3e%2529%2529&version=6.7" class="RktStxLink Sq" data-pltdoc="x"><span class="nobreak">-></span></a></span><span class="stt"> </span><span class="RktSym"><a href="http.html#%28def._%28%28lib._web-server%2Fhttp%2Frequest-structs..rkt%29._request~3f%29%29" class="RktValLink" data-pltdoc="x">request?</a></span><span class="stt"> </span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=data-structure-contracts.html%23%2528form._%2528%2528lib._racket%252Fcontract%252Fprivate%252Fmisc..rkt%2529._any%2529%2529&version=6.7" class="RktStxLink Sq" data-pltdoc="x">any</a></span><span class="RktPn">)</span> that calls the appropriate
<span class="RktVar">dispatch-fun</span> based on the first <span class="RktVar">dispatch-pattern</span>
that matches the request’s URL (and method), the second is a URL-generating
function with the contract <span class="RktPn">(</span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=function-contracts.html%23%2528form._%2528%2528lib._racket%252Fcontract%252Fbase..rkt%2529._-%7E3e%2529%2529&version=6.7" class="RktStxLink Sq" data-pltdoc="x"><span class="nobreak">-></span></a></span><span class="stt"> </span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=procedures.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._procedure%7E3f%2529%2529&version=6.7" class="RktValLink Sq" data-pltdoc="x">procedure?</a></span><span class="stt"> </span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=data-structure-contracts.html%23%2528def._%2528%2528lib._racket%252Fcontract%252Fprivate%252Fmisc..rkt%2529._any%252Fc%2529%2529&version=6.7" class="RktValLink Sq" data-pltdoc="x">any/c</a></span><span class="stt"> </span><span class="RktMeta"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=stx-patterns.html%23%2528form._%2528%2528lib._racket%252Fprivate%252Fstxcase-scheme..rkt%2529._......%2529%2529&version=6.7" class="RktStxLink Sq" data-pltdoc="x">...</a></span><span class="stt"> </span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=strings.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._string%7E3f%2529%2529&version=6.7" class="RktValLink Sq" data-pltdoc="x">string?</a></span><span class="RktPn">)</span> that generates a URL using <span class="RktVar">dispatch-pattern</span> for
the <span class="RktVar">dispatch-fun</span> given as its first argument.</div></p><p>If <span class="RktVar">else-fun</span> is left out, one is provided that calls
<span class="RktPn">(</span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=web-server-internal&rel=dispatch.html%23%2528def._%2528%2528lib._web-server%252Fdispatchers%252Fdispatch..rkt%2529._next-dispatcher%2529%2529&version=6.7" class="RktValLink Sq" data-pltdoc="x">next-dispatcher</a></span><span class="RktPn">)</span> to signal to the Web Server that this
dispatcher does not apply.</p><p>The <span class="RktVar">method</span> syntax is used in a <span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=match.html%23%2528form._%2528%2528lib._racket%252Fmatch..rkt%2529._match%2529%2529&version=6.7" class="RktStxLink Sq" data-pltdoc="x">match</a></span> expression to
match the <span class="RktSym"><a href="http.html#%28def._%28%28lib._web-server%2Fhttp%2Frequest-structs..rkt%29._request-method%29%29" class="RktValLink" data-pltdoc="x">request-method</a></span> part of the incoming request
object. However, since HTTP allows methods to use any case, the byte
string from <span class="RktSym"><a href="http.html#%28def._%28%28lib._web-server%2Fhttp%2Frequest-structs..rkt%29._request-method%29%29" class="RktValLink" data-pltdoc="x">request-method</a></span> is normalized to a lower-case
string. Thus, valid patterns are things like: <span class="RktVal">"get"</span>,
<span class="RktVal">"post"</span>, <span class="RktVal">"head"</span>, <span class="RktPn">(</span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=if.html%23%2528form._%2528%2528lib._racket%252Fprivate%252Fletstx-scheme..rkt%2529._or%2529%2529&version=6.7" class="RktStxLink Sq" data-pltdoc="x">or</a></span><span class="stt"> </span><span class="RktVal">"get"</span><span class="stt"> </span><span class="RktVal">"post"</span><span class="RktPn">)</span>, etc.</p><p>If <span class="RktVar">method</span> is left out, it assumed to apply to requests
without methods and GET methods.</p><p><div class="SIntrapara"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><blockquote class="SubFlow"><div class="RBackgroundLabel SIEHidden"><div class="RBackgroundLabelInner"><p>syntax</p></div></div><table cellspacing="0" cellpadding="0" class="RktBlk RForeground"><tr><td><span class="RktPn">(</span><a name="(form._((lib._web-server/dispatch..rkt)._dispatch-rules+applies))"></a><span title="Provided from: web-server/dispatch | Package: web-server-lib"><span class="RktSym"><a href="#%28form._%28%28lib._web-server%2Fdispatch..rkt%29._dispatch-rules%2Bapplies%29%29" class="RktStxDef RktStxLink" data-pltdoc="x">dispatch-rules+applies</a></span></span></td></tr><tr><td><span class="hspace"> </span><span class="RktVar">dispatch-clause</span><span class="hspace"> </span><span class="RktMeta">...</span></td></tr><tr><td><span class="hspace"> </span><span class="RktVar">maybe-else-clause</span><span class="RktPn">)</span></td></tr></table></blockquote></td></tr></table></blockquote></div><div class="SIntrapara">Like <span class="RktSym"><a href="#%28form._%28%28lib._web-server%2Fdispatch..rkt%29._dispatch-rules%29%29" class="RktStxLink" data-pltdoc="x">dispatch-rules</a></span>, except returns a third value with the contract <span class="RktPn">(</span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=function-contracts.html%23%2528form._%2528%2528lib._racket%252Fcontract%252Fbase..rkt%2529._-%7E3e%2529%2529&version=6.7" class="RktStxLink Sq" data-pltdoc="x"><span class="nobreak">-></span></a></span><span class="stt"> </span><span class="RktSym"><a href="http.html#%28def._%28%28lib._web-server%2Fhttp%2Frequest-structs..rkt%29._request~3f%29%29" class="RktValLink" data-pltdoc="x">request?</a></span><span class="stt"> </span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=booleans.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._boolean%7E3f%2529%2529&version=6.7" class="RktValLink Sq" data-pltdoc="x">boolean?</a></span><span class="RktPn">)</span> that returns
<span class="RktVal">#t</span> if the dispatching rules apply to the request and <span class="RktVal">#f</span> otherwise.</div></p><p><div class="SIntrapara"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><blockquote class="SubFlow"><div class="RBackgroundLabel SIEHidden"><div class="RBackgroundLabelInner"><p>syntax</p></div></div><table cellspacing="0" cellpadding="0" class="RktBlk RForeground"><tr><td><span class="RktPn">(</span><a name="(form._((lib._web-server/dispatch..rkt)._dispatch-case))"></a><span title="Provided from: web-server/dispatch | Package: web-server-lib"><span class="RktSym"><a href="#%28form._%28%28lib._web-server%2Fdispatch..rkt%29._dispatch-case%29%29" class="RktStxDef RktStxLink" data-pltdoc="x">dispatch-case</a></span></span></td></tr><tr><td><span class="hspace"> </span><span class="RktVar">dispatch-clause</span><span class="hspace"> </span><span class="RktMeta">...</span></td></tr><tr><td><span class="hspace"> </span><span class="RktVar">maybe-else-clause</span><span class="RktPn">)</span></td></tr></table></blockquote></td></tr></table></blockquote></div><div class="SIntrapara">Returns a dispatching function as described by <span class="RktSym"><a href="#%28form._%28%28lib._web-server%2Fdispatch..rkt%29._dispatch-rules%29%29" class="RktStxLink" data-pltdoc="x">dispatch-rules</a></span>.</div></p><p><div class="SIntrapara"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><blockquote class="SubFlow"><div class="RBackgroundLabel SIEHidden"><div class="RBackgroundLabelInner"><p>syntax</p></div></div><table cellspacing="0" cellpadding="0" class="RktBlk RForeground"><tr><td><span class="RktPn">(</span><a name="(form._((lib._web-server/dispatch..rkt)._dispatch-url))"></a><span title="Provided from: web-server/dispatch | Package: web-server-lib"><span class="RktSym"><a href="#%28form._%28%28lib._web-server%2Fdispatch..rkt%29._dispatch-url%29%29" class="RktStxDef RktStxLink" data-pltdoc="x">dispatch-url</a></span></span></td></tr><tr><td><span class="hspace"> </span><span class="RktPn">[</span><span class="RktVar">dispatch-pattern</span><span class="hspace"> </span><span class="RktVar">dispatch-fun</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace"> </span><span class="RktMeta">...</span><span class="RktPn">)</span></td></tr></table></blockquote></td></tr><tr><td><span class="stt"> </span></td></tr><tr><td><table cellspacing="0" cellpadding="0" class="argcontract"><tr><td><span class="hspace"> </span></td><td><span class="RktVar">dispatch-fun</span></td><td><span class="hspace"> </span></td><td>:</td><td><span class="hspace"> </span></td><td><span class="RktPn">(</span><span class="RktSym"><a href="http.html#%28def._%28%28lib._web-server%2Fhttp%2Frequest-structs..rkt%29._request~3f%29%29" class="RktValLink" data-pltdoc="x">request?</a></span><span class="hspace"> </span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=data-structure-contracts.html%23%2528def._%2528%2528lib._racket%252Fcontract%252Fprivate%252Fmisc..rkt%2529._any%252Fc%2529%2529&version=6.7" class="RktValLink Sq" data-pltdoc="x">any/c</a></span><span class="hspace"> </span><span class="RktMeta"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=stx-patterns.html%23%2528form._%2528%2528lib._racket%252Fprivate%252Fstxcase-scheme..rkt%2529._......%2529%2529&version=6.7" class="RktStxLink Sq" data-pltdoc="x">...</a></span><span class="hspace"> </span><span class="RktPn">. </span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=function-contracts.html%23%2528form._%2528%2528lib._racket%252Fcontract%252Fbase..rkt%2529._-%7E3e%2529%2529&version=6.7" class="RktStxLink Sq" data-pltdoc="x"><span class="nobreak">-></span></a></span><span class="RktPn"> .</span><span class="hspace"> </span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=data-structure-contracts.html%23%2528form._%2528%2528lib._racket%252Fcontract%252Fprivate%252Fmisc..rkt%2529._any%2529%2529&version=6.7" class="RktStxLink Sq" data-pltdoc="x">any</a></span><span class="RktPn">)</span></td></tr></table></td></tr></table></blockquote></div><div class="SIntrapara">Returns a URL-generating function as described by <span class="RktSym"><a href="#%28form._%28%28lib._web-server%2Fdispatch..rkt%29._dispatch-rules%29%29" class="RktStxLink" data-pltdoc="x">dispatch-rules</a></span>.</div></p><p><div class="SIntrapara"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><blockquote class="SubFlow"><div class="RBackgroundLabel SIEHidden"><div class="RBackgroundLabelInner"><p>procedure</p></div></div><p class="RForeground"><span class="RktPn">(</span><a name="(def._((lib._web-server/dispatch..rkt)._serve/dispatch))"></a><span title="Provided from: web-server/dispatch | Package: web-server-lib"><span class="RktSym"><a href="#%28def._%28%28lib._web-server%2Fdispatch..rkt%29._serve%2Fdispatch%29%29" class="RktValDef RktValLink" data-pltdoc="x">serve/dispatch</a></span></span><span class="hspace"> </span><span class="RktVar">dispatch</span><span class="RktPn">)</span><span class="hspace"> </span>→<span class="hspace"> </span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=void.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._void%2529%2529&version=6.7" class="RktValLink Sq" data-pltdoc="x">void</a></span></p></blockquote></td></tr><tr><td><span class="hspace"> </span><span class="RktVar">dispatch</span><span class="hspace"> </span>:<span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="http.html#%28def._%28%28lib._web-server%2Fhttp%2Frequest-structs..rkt%29._request~3f%29%29" class="RktValLink" data-pltdoc="x">request?</a></span><span class="hspace"> </span><span class="RktPn">. </span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=function-contracts.html%23%2528form._%2528%2528lib._racket%252Fcontract%252Fbase..rkt%2529._-%7E3e%2529%2529&version=6.7" class="RktStxLink Sq" data-pltdoc="x"><span class="nobreak">-></span></a></span><span class="RktPn"> .</span><span class="hspace"> </span><span class="RktSym"><a href="servlet.html#%28def._%28%28lib._web-server%2Fservlet%2Fservlet-structs..rkt%29._can-be-response~3f%29%29" class="RktValLink" data-pltdoc="x">can-be-response?</a></span><span class="RktPn">)</span></td></tr></table></blockquote></div><div class="SIntrapara">Calls <span class="RktSym"><a href="run.html#%28def._%28%28lib._web-server%2Fservlet-env..rkt%29._serve%2Fservlet%29%29" class="RktValLink" data-pltdoc="x">serve/servlet</a></span> with a <span class="RktPn">#:servlet-regexp</span> argument (<span class="RktVal">#rx""</span>) so that every request is handled by <span class="RktVar">dispatch</span>.</div></p><h4 x-source-module="(lib "web-server/scribblings/web-server.scrbl")" x-source-pkg="web-server-doc" x-part-tag=""Imperative_Dispatch_Containers"">5.3<tt> </tt><a name="(part._.Imperative_.Dispatch_.Containers)"></a>Imperative Dispatch Containers</h4><p><span class="RktSym"><a href="#%28form._%28%28lib._web-server%2Fdispatch..rkt%29._dispatch-rules%29%29" class="RktStxLink" data-pltdoc="x">dispatch-rules</a></span> is purely functional. This presents a more declarative interface, but inhibits some programming and modularity patterns. <a name="(tech._container)"></a><span style="font-style: italic">Containers</span> provide an imperative overlay atop <span class="RktSym"><a href="#%28form._%28%28lib._web-server%2Fdispatch..rkt%29._dispatch-rules%29%29" class="RktStxLink" data-pltdoc="x">dispatch-rules</a></span>.</p><p><div class="SIntrapara"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><blockquote class="SubFlow"><div class="RBackgroundLabel SIEHidden"><div class="RBackgroundLabelInner"><p>procedure</p></div></div><p class="RForeground"><span class="RktPn">(</span><a name="(def._((lib._web-server/dispatch..rkt)._container~3f))"></a><span title="Provided from: web-server/dispatch | Package: web-server-lib"><span class="RktSym"><a href="#%28def._%28%28lib._web-server%2Fdispatch..rkt%29._container~3f%29%29" class="RktValDef RktValLink" data-pltdoc="x">container?</a></span></span><span class="hspace"> </span><span class="RktVar">x</span><span class="RktPn">)</span><span class="hspace"> </span>→<span class="hspace"> </span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=booleans.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._boolean%7E3f%2529%2529&version=6.7" class="RktValLink Sq" data-pltdoc="x">boolean?</a></span></p></blockquote></td></tr><tr><td><span class="hspace"> </span><span class="RktVar">x</span><span class="hspace"> </span>:<span class="hspace"> </span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=data-structure-contracts.html%23%2528def._%2528%2528lib._racket%252Fcontract%252Fprivate%252Fmisc..rkt%2529._any%252Fc%2529%2529&version=6.7" class="RktValLink Sq" data-pltdoc="x">any/c</a></span></td></tr></table></blockquote></div><div class="SIntrapara"> Identifies <a href="#%28tech._container%29" class="techoutside" data-pltdoc="x"><span class="techinside">containers</span></a>. </div></p><p><div class="SIntrapara"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><blockquote class="SubFlow"><div class="RBackgroundLabel SIEHidden"><div class="RBackgroundLabelInner"><p>syntax</p></div></div><p class="RForeground"><span class="RktPn">(</span><a name="(form._((lib._web-server/dispatch..rkt)._define-container))"></a><span title="Provided from: web-server/dispatch | Package: web-server-lib"><span class="RktSym"><a href="#%28form._%28%28lib._web-server%2Fdispatch..rkt%29._define-container%29%29" class="RktStxDef RktStxLink" data-pltdoc="x">define-container</a></span></span><span class="hspace"> </span><span class="RktVar">container-id</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktVar">dispatch-id</span><span class="hspace"> </span><span class="RktVar">url-id</span><span class="RktPn">)</span><span class="RktPn">)</span></p></blockquote></td></tr></table></blockquote></div><div class="SIntrapara">Defines <span class="RktVar">container-id</span> as a container as well as <span class="RktVar">dispatch-id</span> as its dispatching function and <span class="RktVar">url-id</span> as its URL lookup function.</div></p><p><div class="SIntrapara"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><blockquote class="SubFlow"><div class="RBackgroundLabel SIEHidden"><div class="RBackgroundLabelInner"><p>syntax</p></div></div><p class="RForeground"><span class="RktPn">(</span><a name="(form._((lib._web-server/dispatch..rkt)._dispatch-rules!))"></a><span title="Provided from: web-server/dispatch | Package: web-server-lib"><span class="RktSym"><a href="#%28form._%28%28lib._web-server%2Fdispatch..rkt%29._dispatch-rules%21%29%29" class="RktStxDef RktStxLink" data-pltdoc="x">dispatch-rules!</a></span></span><span class="hspace"> </span><span class="RktVar">container-expr</span><span class="hspace"> </span><span class="RktPn">[</span><span class="RktVar">dispatch-pattern</span><span class="hspace"> </span><span class="RktVar">dispatch-fun</span><span class="RktPn">]</span><span class="hspace"> </span><span class="RktMeta">...</span><span class="RktPn">)</span></p></blockquote></td></tr></table></blockquote></div><div class="SIntrapara">Like <span class="RktSym"><a href="#%28form._%28%28lib._web-server%2Fdispatch..rkt%29._dispatch-rules%29%29" class="RktStxLink" data-pltdoc="x">dispatch-rules</a></span>, but imperatively adds the patterns to the container specified by <span class="RktVar">container-expr</span>. The new rules are consulted <span style="font-style: italic">before</span> any rules already in the container. </div></p><h4 x-source-module="(lib "web-server/scribblings/web-server.scrbl")" x-source-pkg="web-server-doc" x-part-tag=""Built-in_URL_patterns"">5.4<tt> </tt><a name="(part._.Built-in_.U.R.L_patterns)"></a>Built-in URL patterns</h4><p><a href="" class="RktModLink" data-pltdoc="x"><span class="RktSym">web-server/dispatch</span></a> builds in a few useful URL component patterns.</p><p><div class="SIntrapara"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><blockquote class="SubFlow"><div class="RBackgroundLabel SIEHidden"><div class="RBackgroundLabelInner"><p>syntax</p></div></div><p class="RForeground"><span class="RktPn">(</span><a name="(form._((lib._web-server/dispatch..rkt)._number-arg))"></a><span title="Provided from: web-server/dispatch | Package: web-server-lib"><span class="RktSym"><a href="#%28form._%28%28lib._web-server%2Fdispatch..rkt%29._number-arg%29%29" class="RktStxDef RktStxLink" data-pltdoc="x">number-arg</a></span></span><span class="RktPn">)</span></p></blockquote></td></tr></table></blockquote></div><div class="SIntrapara">A <a href="#%28tech._bi._directional._match._expander%29" class="techoutside" data-pltdoc="x"><span class="techinside">bi-directional match expander</span></a> that parses a <span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=number-types.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._number%7E3f%2529%2529&version=6.7" class="RktValLink Sq" data-pltdoc="x">number?</a></span> from the URL and generates a URL with a number’s encoding as a string.</div></p><p><div class="SIntrapara"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><blockquote class="SubFlow"><div class="RBackgroundLabel SIEHidden"><div class="RBackgroundLabelInner"><p>syntax</p></div></div><p class="RForeground"><span class="RktPn">(</span><a name="(form._((lib._web-server/dispatch..rkt)._integer-arg))"></a><span title="Provided from: web-server/dispatch | Package: web-server-lib"><span class="RktSym"><a href="#%28form._%28%28lib._web-server%2Fdispatch..rkt%29._integer-arg%29%29" class="RktStxDef RktStxLink" data-pltdoc="x">integer-arg</a></span></span><span class="RktPn">)</span></p></blockquote></td></tr></table></blockquote></div><div class="SIntrapara">A <a href="#%28tech._bi._directional._match._expander%29" class="techoutside" data-pltdoc="x"><span class="techinside">bi-directional match expander</span></a> that parses a <span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=number-types.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._integer%7E3f%2529%2529&version=6.7" class="RktValLink Sq" data-pltdoc="x">integer?</a></span> from the URL and generates a URL with a integer’s encoding as a string.</div></p><p><div class="SIntrapara"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><blockquote class="SubFlow"><div class="RBackgroundLabel SIEHidden"><div class="RBackgroundLabelInner"><p>syntax</p></div></div><p class="RForeground"><span class="RktPn">(</span><a name="(form._((lib._web-server/dispatch..rkt)._real-arg))"></a><span title="Provided from: web-server/dispatch | Package: web-server-lib"><span class="RktSym"><a href="#%28form._%28%28lib._web-server%2Fdispatch..rkt%29._real-arg%29%29" class="RktStxDef RktStxLink" data-pltdoc="x">real-arg</a></span></span><span class="RktPn">)</span></p></blockquote></td></tr></table></blockquote></div><div class="SIntrapara">A <a href="#%28tech._bi._directional._match._expander%29" class="techoutside" data-pltdoc="x"><span class="techinside">bi-directional match expander</span></a> that parses a <span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=number-types.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._real%7E3f%2529%2529&version=6.7" class="RktValLink Sq" data-pltdoc="x">real?</a></span> from the URL and generates a URL with a real’s encoding as a string.</div></p><p><div class="SIntrapara"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><blockquote class="SubFlow"><div class="RBackgroundLabel SIEHidden"><div class="RBackgroundLabelInner"><p>syntax</p></div></div><p class="RForeground"><span class="RktPn">(</span><a name="(form._((lib._web-server/dispatch..rkt)._string-arg))"></a><span title="Provided from: web-server/dispatch | Package: web-server-lib"><span class="RktSym"><a href="#%28form._%28%28lib._web-server%2Fdispatch..rkt%29._string-arg%29%29" class="RktStxDef RktStxLink" data-pltdoc="x">string-arg</a></span></span><span class="RktPn">)</span></p></blockquote></td></tr></table></blockquote></div><div class="SIntrapara">A <a href="#%28tech._bi._directional._match._expander%29" class="techoutside" data-pltdoc="x"><span class="techinside">bi-directional match expander</span></a> that parses a <span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=strings.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._string%7E3f%2529%2529&version=6.7" class="RktValLink Sq" data-pltdoc="x">string?</a></span> from the URL and generates a URL containing the string.</div></p><p><div class="SIntrapara"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><blockquote class="SubFlow"><div class="RBackgroundLabel SIEHidden"><div class="RBackgroundLabelInner"><p>syntax</p></div></div><p class="RForeground"><span class="RktPn">(</span><a name="(form._((lib._web-server/dispatch..rkt)._symbol-arg))"></a><span title="Provided from: web-server/dispatch | Package: web-server-lib"><span class="RktSym"><a href="#%28form._%28%28lib._web-server%2Fdispatch..rkt%29._symbol-arg%29%29" class="RktStxDef RktStxLink" data-pltdoc="x">symbol-arg</a></span></span><span class="RktPn">)</span></p></blockquote></td></tr></table></blockquote></div><div class="SIntrapara">A <a href="#%28tech._bi._directional._match._expander%29" class="techoutside" data-pltdoc="x"><span class="techinside">bi-directional match expander</span></a> that parses a <span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=symbols.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._symbol%7E3f%2529%2529&version=6.7" class="RktValLink Sq" data-pltdoc="x">symbol?</a></span> from the URL and generates a URL with a symbol’s encoding as a string.</div></p><h4 x-source-module="(lib "web-server/scribblings/web-server.scrbl")" x-source-pkg="web-server-doc" x-part-tag=""Extending_web-server_dispatch"">5.5<tt> </tt><a name="(part._.Extending_web-server_dispatch)"></a><a name="(mod-path._web-server/dispatch/extend)"></a>Extending <a href="" class="RktModLink" data-pltdoc="x"><span class="RktSym">web-server/dispatch</span></a></h4><p><table cellspacing="0" cellpadding="0" class="defmodule"><tr><td align="left" colspan="2"><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=require.html%23%2528form._%2528%2528lib._racket%252Fprivate%252Fbase..rkt%2529._require%2529%2529&version=6.7" class="RktStxLink Sq" data-pltdoc="x">require</a></span><span class="stt"> </span><a href="#%28mod-path._web-server%2Fdispatch%2Fextend%29" class="RktModLink" data-pltdoc="x"><span class="RktSym">web-server/dispatch/extend</span></a><span class="RktPn">)</span></td></tr><tr><td align="left"> </td><td align="right"><span class="RpackageSpec"><span class="Smaller"> package:</span> <span class="stt">web-server-lib</span></span></td></tr></table></p><p>You can create new URL component patterns by defining <a href="#%28tech._bi._directional._match._expander%29" class="techoutside" data-pltdoc="x"><span class="techinside">bi-directional match expanders</span></a>.</p><p><div class="SIntrapara"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><blockquote class="SubFlow"><div class="RBackgroundLabel SIEHidden"><div class="RBackgroundLabelInner"><p>syntax</p></div></div><p class="RForeground"><span class="RktPn">(</span><a name="(form._((lib._web-server/dispatch/extend..rkt)._define-bidi-match-expander))"></a><span title="Provided from: web-server/dispatch/extend | Package: web-server-lib"><span class="RktSym"><a href="#%28form._%28%28lib._web-server%2Fdispatch%2Fextend..rkt%29._define-bidi-match-expander%29%29" class="RktStxDef RktStxLink" data-pltdoc="x">define-bidi-match-expander</a></span></span><span class="hspace"> </span><span class="RktVar">id</span><span class="hspace"> </span><span class="RktVar">in-xform</span><span class="hspace"> </span><span class="RktVar">out-xform</span><span class="RktPn">)</span></p></blockquote></td></tr></table></blockquote></div><div class="SIntrapara">Binds <span class="RktVar">id</span> to a <a name="(tech._bi._directional._match._expander)"></a><span style="font-style: italic">bi-directional match expander</span>
where <span class="RktVar">in-xform</span> is a match expander (defined by <span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=match.html%23%2528form._%2528%2528lib._racket%252Fmatch..rkt%2529._define-match-expander%2529%2529&version=6.7" class="RktStxLink Sq" data-pltdoc="x">define-match-expander</a></span>) that is used when parsing URLs
and <span class="RktVar">out-xform</span> is one used when generating URLs.</div></p><p>Both <span class="RktVar">in-xform</span> and <span class="RktVar">out-xform</span> should use the syntax <span class="RktPn">(</span><span class="RktVar">xform</span><span class="stt"> </span><span class="RktSym">arg</span><span class="stt"> </span><span class="RktMeta"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=stx-patterns.html%23%2528form._%2528%2528lib._racket%252Fprivate%252Fstxcase-scheme..rkt%2529._......%2529%2529&version=6.7" class="RktStxLink Sq" data-pltdoc="x">...</a></span><span class="stt"> </span><span class="RktVar">id</span><span class="RktPn">)</span> where the <span class="RktSym">arg</span>s are
specific to <span class="RktVar">id</span> and compatible with both <span class="RktVar">in-xform</span> and <span class="RktVar">out-xform</span>. <span class="RktVar">id</span> will typically be provided
automatically by <span class="RktSym"><a href="#%28form._%28%28lib._web-server%2Fdispatch..rkt%29._dispatch-rules%29%29" class="RktStxLink" data-pltdoc="x">dispatch-rules</a></span>.</p><p><div class="SIntrapara"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><blockquote class="SubFlow"><div class="RBackgroundLabel SIEHidden"><div class="RBackgroundLabelInner"><p>syntax</p></div></div><p class="RForeground"><a name="(form._((lib._web-server/dispatch/extend..rkt)._bidi-match-going-in~3f))"></a><span title="Provided from: web-server/dispatch/extend | Package: web-server-lib"><span class="RktSym"><a href="#%28form._%28%28lib._web-server%2Fdispatch%2Fextend..rkt%29._bidi-match-going-in~3f%29%29" class="RktStxDef RktStxLink" data-pltdoc="x">bidi-match-going-in?</a></span></span></p></blockquote></td></tr></table></blockquote></div><div class="SIntrapara">A <a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=stxparam.html%23%2528tech._syntax._parameter%2529&version=6.7" class="techoutside Sq" data-pltdoc="x"><span class="techinside">syntax parameter</span></a> used by <a href="#%28tech._bi._directional._match._expander%29" class="techoutside" data-pltdoc="x"><span class="techinside">bi-directional match expanders</span></a> to determine if a URL is being parsed or generated.</div></p><p>When defining new patterns, you may find it useful to use these helper functions:</p><p><div class="SIntrapara"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><blockquote class="SubFlow"><div class="RBackgroundLabel SIEHidden"><div class="RBackgroundLabelInner"><p>syntax</p></div></div><p class="RForeground"><span class="RktPn">(</span><a name="(form._((lib._web-server/dispatch/extend..rkt)._define-coercion-match-expander))"></a><span title="Provided from: web-server/dispatch/extend | Package: web-server-lib"><span class="RktSym"><a href="#%28form._%28%28lib._web-server%2Fdispatch%2Fextend..rkt%29._define-coercion-match-expander%29%29" class="RktStxDef RktStxLink" data-pltdoc="x">define-coercion-match-expander</a></span></span><span class="hspace"> </span><span class="RktVar">id</span><span class="hspace"> </span><span class="RktVar">test?</span><span class="hspace"> </span><span class="RktVar">coerce</span><span class="RktPn">)</span></p></blockquote></td></tr></table></blockquote></div><div class="SIntrapara">Binds <span class="RktVar">id</span> to a match expander that expands <span class="RktPn">(</span><span class="RktVar">id</span><span class="stt"> </span><span class="RktVar">x</span><span class="RktPn">)</span> to
<span class="RktPn">(</span><span class="RktSym">?</span><span class="stt"> </span><span class="RktVar">test?</span><span class="stt"> </span><span class="RktPn">(</span><span class="RktSym">app</span><span class="stt"> </span><span class="RktVar">coerce</span><span class="stt"> </span><span class="RktVar">x</span><span class="RktPn">)</span><span class="RktPn">)</span> (i.e., uses <span class="RktVar">test?</span> to determine if the pattern matches and <span class="RktVar">coerce</span> to transform the binding.)</div></p><p><div class="SIntrapara"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><blockquote class="SubFlow"><div class="RBackgroundLabel SIEHidden"><div class="RBackgroundLabelInner"><p>procedure</p></div></div><p class="RForeground"><span class="RktPn">(</span><a name="(def._((lib._web-server/dispatch/extend..rkt)._make-coerce-safe~3f))"></a><span title="Provided from: web-server/dispatch/extend | Package: web-server-lib"><span class="RktSym"><a href="#%28def._%28%28lib._web-server%2Fdispatch%2Fextend..rkt%29._make-coerce-safe~3f%29%29" class="RktValDef RktValLink" data-pltdoc="x">make-coerce-safe?</a></span></span><span class="hspace"> </span><span class="RktVar">coerce</span><span class="RktPn">)</span><span class="hspace"> </span>→<span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=data-structure-contracts.html%23%2528def._%2528%2528lib._racket%252Fcontract%252Fprivate%252Fmisc..rkt%2529._any%252Fc%2529%2529&version=6.7" class="RktValLink Sq" data-pltdoc="x">any/c</a></span><span class="hspace"> </span><span class="RktPn">. </span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=function-contracts.html%23%2528form._%2528%2528lib._racket%252Fcontract%252Fbase..rkt%2529._-%7E3e%2529%2529&version=6.7" class="RktStxLink Sq" data-pltdoc="x"><span class="nobreak">-></span></a></span><span class="RktPn"> .</span><span class="hspace"> </span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=booleans.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._boolean%7E3f%2529%2529&version=6.7" class="RktValLink Sq" data-pltdoc="x">boolean?</a></span><span class="RktPn">)</span></p></blockquote></td></tr><tr><td><span class="hspace"> </span><span class="RktVar">coerce</span><span class="hspace"> </span>:<span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=data-structure-contracts.html%23%2528def._%2528%2528lib._racket%252Fcontract%252Fprivate%252Fmisc..rkt%2529._any%252Fc%2529%2529&version=6.7" class="RktValLink Sq" data-pltdoc="x">any/c</a></span><span class="hspace"> </span><span class="RktPn">. </span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=function-contracts.html%23%2528form._%2528%2528lib._racket%252Fcontract%252Fbase..rkt%2529._-%7E3e%2529%2529&version=6.7" class="RktStxLink Sq" data-pltdoc="x"><span class="nobreak">-></span></a></span><span class="RktPn"> .</span><span class="hspace"> </span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=data-structure-contracts.html%23%2528def._%2528%2528lib._racket%252Fcontract%252Fprivate%252Fmisc..rkt%2529._any%252Fc%2529%2529&version=6.7" class="RktValLink Sq" data-pltdoc="x">any/c</a></span><span class="RktPn">)</span></td></tr></table></blockquote></div><div class="SIntrapara">Returns a function that returns <span class="RktVal">#t</span> if <span class="RktVar">coerce</span> would not throw an exception or return <span class="RktVal">#f</span> on its input.</div></p><p><div class="SIntrapara">Examples:</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="stt">> </span><span class="RktPn">(</span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=define.html%23%2528form._%2528%2528lib._racket%252Fprivate%252Fbase..rkt%2529._define%2529%2529&version=6.7" class="RktStxLink Sq" data-pltdoc="x">define</a></span><span class="hspace"> </span><span class="RktSym">string->number?</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="#%28def._%28%28lib._web-server%2Fdispatch%2Fextend..rkt%29._make-coerce-safe~3f%29%29" class="RktValLink" data-pltdoc="x">make-coerce-safe?</a></span><span class="hspace"> </span><span class="RktSym"><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=reference&rel=generic-numbers.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._string-%7E3enumber%2529%2529&version=6.7" class="RktValLink Sq" data-pltdoc="x">string->number</a></span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="stt">> </span><span class="RktPn">(</span><span class="RktSym">string->number?</span><span class="hspace"> </span><span class="RktVal">"1"</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">#t</span></p></td></tr><tr><td><span class="stt">> </span><span class="RktPn">(</span><span class="RktSym">string->number?</span><span class="hspace"> </span><span class="RktVal">"1.2"</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">#t</span></p></td></tr><tr><td><span class="stt">> </span><span class="RktPn">(</span><span class="RktSym">string->number?</span><span class="hspace"> </span><span class="RktVal">"+inf.0"</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">#t</span></p></td></tr><tr><td><span class="stt">> </span><span class="RktPn">(</span><span class="RktSym">string->number?</span><span class="hspace"> </span><span class="RktVal">"one"</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">#f</span></p></td></tr></table></blockquote></div></p><div class="navsetbottom"><span class="navleft"><form class="searchform"><input class="searchbox" style="color: #888;" type="text" value="...search manuals..." title="Enter a search string to search the manuals" onkeypress="return DoSearchKey(event, this, "6.7", "../");" onfocus="this.style.color="black"; this.style.textAlign="left"; if (this.value == "...search manuals...") this.value="";" onblur="if (this.value.match(/^ *$/)) { this.style.color="#888"; this.style.textAlign="center"; this.value="...search manuals..."; }"/></form> <a href="../index.html" title="up to the documentation top" data-pltdoc="x" onclick="return GotoPLTRoot("6.7");">top</a></span><span class="navright"> <a href="http.html" title="backward to "4 HTTP: Hypertext Transfer Protocol"" data-pltdoc="x">← prev</a> <a href="index.html" title="up to "Web Applications in Racket"" data-pltdoc="x">up</a> <a href="formlets.html" title="forward to "6 Formlets: Functional Form Abstraction"" data-pltdoc="x">next →</a></span> </div></div></div><div id="contextindicator"> </div></body></html>
|