Liking cljdoc? Tell your friends :D

fnhouse.routes

A simple and efficient library for routing an API of fnhouse handlers (see fnhouse.handlers). The sole entry point to the ns is the 'root-handler' fn.

Paths can be concrete (simple strings to be matched exactly), or can contain one or more uri arguments specified with colons.

For example, the path /a/b/c only matches the same literal URI, but the path /a/:b/c/:d can match any path with non-empty segments that don't contain slashes for :b and :c. I.e., it can match /a/123/c/asdf but not /a/123/c/ or /a/b1/b2/c/d. The segments matching uri arguments are inserted into the request as :uri-args, url-decoded for example {:b "123" :d "asd f"} for /a/123/c/as%20df.

A path can also contain a single trailing 'wildcard' uri-arg, which can match any number of trailing segments in the uri. For example, /a/:** can match /a, /a/b, or /a/b/c/d. The wildcard match is included in the :uri-args in the request, e.g. {:** "b/c/d"}, but is not url-decoded.

Routing is performed with an efficient hierarchical algorithm, whose runtime is independent of the number of handler for exact matches, and can be much better than a linear traversal of all methods in almost every situation.

If multiple handlers can match a URI, the precedence rules are specified hierarchically over segments. At each level, the lookup prioritizes literal matches over single-wildcards, and single-wildcards over multiple-wildcards. The search will backtrack to try all possible matching routes.

A simple and efficient library for routing an API of fnhouse
handlers (see fnhouse.handlers).  The sole entry point to the ns
is the 'root-handler' fn.

Paths can be concrete (simple strings to be matched exactly), or
can contain one or more uri arguments specified with colons.

For example, the path /a/b/c only matches the same literal URI, but
the path /a/:b/c/:d can match any path with non-empty segments that
don't contain slashes for :b and :c.  I.e., it can match
/a/123/c/asdf but not /a/123/c/ or /a/b1/b2/c/d.  The segments
matching uri arguments are inserted into the request as :uri-args,
url-decoded for example {:b "123" :d "asd f"} for /a/123/c/as%20df.

A path can also contain a single trailing 'wildcard' uri-arg, which
can match any number of trailing segments in the uri.  For example,
/a/:** can match /a, /a/b, or /a/b/c/d.  The wildcard match is
included in the :uri-args in the request, e.g. {:** "b/c/d"},
but is not url-decoded.

Routing is performed with an efficient hierarchical algorithm,
whose runtime is independent of the number of handler for exact
matches, and can be much better than a linear traversal of all methods
in almost every situation.

If multiple handlers can match a URI, the precedence rules are
specified hierarchically over segments. At each level, the lookup
prioritizes literal matches over single-wildcards, and
single-wildcards over multiple-wildcards.  The search will
backtrack to try all possible matching routes.
raw docstring

+multiple-wildcard+clj

Matches one or more route segments

Matches one or more route segments
sourceraw docstring

+single-wildcard+clj

Matches a single route segment

Matches a single route segment
sourceraw docstring

build-prefix-mapclj

(build-prefix-map annotated-handlers)

Build a prefix map from a set of handlers, for efficient request routing via prefix-lookup.

Build a prefix map from a set of handlers, for efficient request routing via prefix-lookup.
sourceraw docstring

match-tokensclj

(match-tokens path)

Inputs: [path] Returns: [(s/either String (s/enum +single-wildcard+ +multiple-wildcard+))]

Parse a declared handler path into a token sequence for efficient route matching, where equivalent uri arg types are collapsed to a single token.

Inputs: [path]
Returns: [(s/either String (s/enum +single-wildcard+ +multiple-wildcard+))]

Parse a declared handler path into a token sequence for efficient route matching,
 where equivalent uri arg types are collapsed to a single token.
sourceraw docstring

prefix-lookupclj

(prefix-lookup node path-segments request-method)
(prefix-lookup node path-segments request-method uri-args)

Inputs: ([node path-segments request-method] [node path-segments request-method uri-args])

Recursively looks up the most specific handler matching the request path and method.

Inputs: ([node path-segments request-method] [node path-segments request-method uri-args])

Recursively looks up the most specific handler matching the request path and method.
sourceraw docstring

root-handlerclj

(root-handler handlers)

Inputs: [handlers :- [schemas/AnnotatedHandler]]

Takes a seq of handlers, returns a single handler that routes the request to the appropriate handler while binding :uri-args in the request to the appropriate path segments.

Inputs: [handlers :- [schemas/AnnotatedHandler]]

Takes a seq of handlers, returns a single handler that routes the request to the
 appropriate handler while binding :uri-args in the request to the appropriate
 path segments.
sourceraw docstring

split-pathclj

(split-path path)

Inputs: [path :- String] Returns: [String]

Split a path into a sequence of segment tokens

Inputs: [path :- String]
Returns: [String]

Split a path into a sequence of segment tokens
sourceraw docstring

uri-arg-ksclj

(uri-arg-ks path)

Inputs: [path] Returns: [s/Keyword]

Parse out the uri arg ks from a declared handler path

Inputs: [path]
Returns: [s/Keyword]

Parse out the uri arg ks from a declared handler path
sourceraw docstring

url-decodeclj

(url-decode encoded)

Returns an UTF-8 URL encoded version of the given string.

Returns an UTF-8 URL encoded version of the given string.
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close