aboutsummaryrefslogtreecommitdiffstats
path: root/manual/cowboy_router.md
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2013-05-17 13:13:27 +0200
committerLoïc Hoguin <[email protected]>2013-05-17 13:13:27 +0200
commit666c59bc422172562673916ed3a8a796c4f9fbf4 (patch)
treef561151846de077513fa767edc10165a469d09ef /manual/cowboy_router.md
parent0e0ec7b1203a8490ee9a876f9274fe0c64e708f8 (diff)
downloadcowboy-666c59bc422172562673916ed3a8a796c4f9fbf4.tar.gz
cowboy-666c59bc422172562673916ed3a8a796c4f9fbf4.tar.bz2
cowboy-666c59bc422172562673916ed3a8a796c4f9fbf4.zip
Add the Cowboy Function Reference
The manual details every stable public functions of Cowboy.
Diffstat (limited to 'manual/cowboy_router.md')
-rw-r--r--manual/cowboy_router.md68
1 files changed, 68 insertions, 0 deletions
diff --git a/manual/cowboy_router.md b/manual/cowboy_router.md
new file mode 100644
index 0000000..1c6dc04
--- /dev/null
+++ b/manual/cowboy_router.md
@@ -0,0 +1,68 @@
+cowboy_router
+=============
+
+The `cowboy_router` middleware maps the requested host and
+path to the handler to be used for processing the request.
+It uses the dispatch rules compiled from the routes given
+to the `compile/1` function for this purpose. It adds the
+handler name and options to the environment as the values
+`handler` and `handler_opts` respectively.
+
+Environment input:
+ * dispatch = dispatch_rules()
+
+Environment output:
+ * handler = module()
+ * handler_opts = any()
+
+Types
+-----
+
+### bindings() = [{atom(), binary()}]
+
+> List of bindings found during routing.
+
+### constraints() = [IntConstraint | FunConstraint]
+
+> Types:
+> * IntConstraint = {atom(), int}
+> * FunConstraint = {atom(), function, Fun}
+> * Fun = fun((binary()) -> true | {true, any()} | false)
+>
+> List of constraints to apply to the bindings.
+>
+> The int constraint will convert the binding to an integer.
+> The fun constraint allows writing custom code for checking
+> the bindings. Returning a new value from that fun allows
+> replacing the current binding with a new value.
+
+### dispatch_rules() - opaque to the user
+
+> Rules for dispatching request used by Cowboy.
+
+### routes() = [{Host, Paths} | {Host, constraints(), Paths}]
+
+> Types:
+> * Host = Path = '_' | iodata()
+> * Paths = [{Path, Handler, Opts} | {Path, constraints(), Handler, Opts}]
+> * Handler = module()
+> * Opts = any()
+>
+> Human readable list of routes mapping hosts and paths to handlers.
+>
+> The syntax for routes is defined in the user guide.
+
+### tokens() = [binary()]
+
+> List of host_info and path_info tokens found during routing.
+
+Exports
+-------
+
+### compile(Routes) -> Dispatch
+
+> Types:
+> * Routes = routes()
+> * Dispatch = dispatch_rules()
+>
+> Compile the routes for use by Cowboy.