From 627454fb84124957a02ed8c6c79812b79f71a7f8 Mon Sep 17 00:00:00 2001 From: Automatic build Date: Sun, 29 Oct 2017 07:30:23 +0000 Subject: [PATCH] Build book from commit 15bfb7b475aebbf1000c94fdf2038b65ded2c20e [skip ci] --- advanced/configuring_routers.html | 533 +++++++++++++++++++++++++ advanced/index.html | 495 +++++++++++++++++++++++ advanced/route_conflicts.html | 534 +++++++++++++++++++++++++ advanced/route_validation.html | 644 ++++++++++++++++++++++++++++++ basics/different_routers.html | 521 ++++++++++++++++++++++++ basics/index.html | 498 +++++++++++++++++++++++ basics/name_based_routing.html | 518 ++++++++++++++++++++++++ basics/path_based_routing.html | 506 +++++++++++++++++++++++ basics/route_data.html | 531 ++++++++++++++++++++++++ basics/route_syntax.html | 543 +++++++++++++++++++++++++ basics/router.html | 514 ++++++++++++++++++++++++ index.html | 90 +++-- ring/compiling_middleware.html | 546 +++++++++++++++++++++++++ ring/dynamic_extensions.html | 525 ++++++++++++++++++++++++ ring/index.html | 496 +++++++++++++++++++++++ ring/parameter_coercion.html | 565 ++++++++++++++++++++++++++ ring/ring.html | 574 ++++++++++++++++++++++++++ search_index.json | 2 +- 18 files changed, 8592 insertions(+), 43 deletions(-) create mode 100644 advanced/configuring_routers.html create mode 100644 advanced/index.html create mode 100644 advanced/route_conflicts.html create mode 100644 advanced/route_validation.html create mode 100644 basics/different_routers.html create mode 100644 basics/index.html create mode 100644 basics/name_based_routing.html create mode 100644 basics/path_based_routing.html create mode 100644 basics/route_data.html create mode 100644 basics/route_syntax.html create mode 100644 basics/router.html create mode 100644 ring/compiling_middleware.html create mode 100644 ring/dynamic_extensions.html create mode 100644 ring/index.html create mode 100644 ring/parameter_coercion.html create mode 100644 ring/ring.html diff --git a/advanced/configuring_routers.html b/advanced/configuring_routers.html new file mode 100644 index 00000000..70f766b1 --- /dev/null +++ b/advanced/configuring_routers.html @@ -0,0 +1,533 @@ + + + + + + + Configuring routers · GitBook + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + +
+ +
+ +
+ + + + + + + + +
+
+ +
+
+ +
+ +

Configuring Routers

+

Routers can be configured via options. Options allow things like clojure.spec validation for meta-data and fast, compiled handlers. The following options are available for the reitit.core/router:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
keydescription
:pathBase-path for routes
:routesInitial resolved routes (default [])
:metaInitial expanded route-meta vector (default [])
:expandFunction of arg opts => meta to expand route arg to route meta-data (default reitit.core/expand)
:coerceFunction of route opts => route to coerce resolved route, can throw or return nil
:compileFunction of route opts => result to compile a route handler
:conflictsFunction of {route #{route}} => side-effect to handle conflicting routes (default reitit.core/throw-on-conflicts!)
:routerFunction of routes opts => router to override the actual router implementation
+ + +
+ +
+
+
+ +

results matching ""

+
    + +
    +
    + +

    No results matching ""

    + +
    +
    +
    + +
    +
    + +
    + + + + + + + + + + + + + + +
    + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/advanced/index.html b/advanced/index.html new file mode 100644 index 00000000..cc5afa41 --- /dev/null +++ b/advanced/index.html @@ -0,0 +1,495 @@ + + + + + + + Advanced · GitBook + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + + + + + +
    + +
    + +
    + + + + + + + + +
    +
    + +
    +
    + +
    + +

    Advanced

    + + + +
    + +
    +
    +
    + +

    results matching ""

    +
      + +
      +
      + +

      No results matching ""

      + +
      +
      +
      + +
      +
      + +
      + + + + + + + + + + + + + + +
      + + +
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/advanced/route_conflicts.html b/advanced/route_conflicts.html new file mode 100644 index 00000000..2778821d --- /dev/null +++ b/advanced/route_conflicts.html @@ -0,0 +1,534 @@ + + + + + + + Route conflicts · GitBook + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      +
      + + + + + + + + +
      + +
      + +
      + + + + + + + + +
      +
      + +
      +
      + +
      + +

      Route conflicts

      +

      Many routing libraries allow single path lookup could match multiple routes. Usually, first match is used. This is not good, especially if route tree is merged from multiple sources - routes might regress to be unreachable without a warning.

      +

      Reitit resolves this by running explicit conflicit resolution when a Router is created. Conflicting routes are passed into a :conflicts callback. Default implementation throws ex-info with a descriptive message.

      +

      Examples routes with conflicts:

      +
      (require '[reitit.core :as reitit])
      +
      +(def routes
      +  [["/ping"]
      +   ["/:user-id/orders"]
      +   ["/bulk/:bulk-id"]
      +   ["/public/*path"]
      +   ["/:version/status"]])
      +
      +

      By default, ExceptionInfo is thrown:

      +
      (reitit/router routes)
      +; CompilerException clojure.lang.ExceptionInfo: Router contains conflicting routes:
      +;
      +;    /:user-id/orders
      +; -> /public/*path
      +; -> /bulk/:bulk-id
      +;
      +;    /bulk/:bulk-id
      +; -> /:version/status
      +;
      +;    /public/*path
      +; -> /:version/status
      +;
      +
      +

      Just logging the conflicts:

      +
      (reitit/router
      +  routes
      +  {:conflicts (comp println reitit/conflicts-str)})
      +; Router contains conflicting routes:
      +;
      +;    /:user-id/orders
      +; -> /public/*path
      +; -> /bulk/:bulk-id
      +;
      +;    /bulk/:bulk-id
      +; -> /:version/status
      +;
      +;    /public/*path
      +; -> /:version/status
      +;
      +
      + + +
      + +
      +
      +
      + +

      results matching ""

      +
        + +
        +
        + +

        No results matching ""

        + +
        +
        +
        + +
        +
        + +
        + + + + + + + + + + + + + + +
        + + +
        + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/advanced/route_validation.html b/advanced/route_validation.html new file mode 100644 index 00000000..af8cd482 --- /dev/null +++ b/advanced/route_validation.html @@ -0,0 +1,644 @@ + + + + + + + Route Validation · GitBook + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
        +
        + + + + + + + + +
        + +
        + +
        + + + + + + + + +
        +
        + +
        +
        + +
        + +

        Route validation

        +

        Namespace reitit.spec contains clojure.spec definitions for raw-routes, routes, router and router options.

        +

        NOTE: Use of specs requires to use one of the following:

        +
          +
        • [org.clojure/clojurescript "1.9.660"]
        • +
        • [org.clojure/clojure "1.9.0-alpha19"]
        • +
        • [clojure-future-spec "1.9.0-alpha17"] (Clojure 1.8)
        • +
        +

        At runtime

        +

        If route trees are generated at runtime (e.g. from external source like the database), one can use directly the clojure.spec functions.

        +
        (require '[clojure.spec.alpha :as s])
        +(require '[reitit.spec :as spec])
        +
        +(def routes-from-db
        +  ["tenant1" ::tenant1])
        +
        +(s/valid? ::spec/raw-routes routes-from-db)
        +; false
        +
        +(s/explain ::spec/raw-routes routes-from-db)
        +; In: [0] val: "tenant1" fails spec: :reitit.spec/path at: [:route :path] predicate: (or (blank? %) (starts-with? % "/"))
        +; In: [0] val: "tenant1" fails spec: :reitit.spec/raw-route at: [:routes] predicate: (cat :path :reitit.spec/path :arg (? :reitit.spec/arg) :childs (* (and (nilable :reitit.spec/raw-route))))
        +; In: [1] val: :user/tenant1 fails spec: :reitit.spec/raw-route at: [:routes] predicate: (cat :path :reitit.spec/path :arg (? :reitit.spec/arg) :childs (* (and (nilable :reitit.spec/raw-route))))
        +; :clojure.spec.alpha/spec  :reitit.spec/raw-routes
        +; :clojure.spec.alpha/value  ["tenant1" :user/tenant1]
        +
        +

        At development time

        +

        reitit.core/router can be instrumented and use something like expound to pretty-print the spec problems.

        +

        First add a :dev dependency to:

        +
        [expound "0.3.0"]
        +
        +

        Some bootstrapping:

        +
        (require '[clojure.spec.test.alpha :as stest])
        +(require '[expound.alpha :as expound])
        +(require '[clojure.spec.alpha :as s])
        +(require '[reitit.spec])
        +
        +(stest/instrument `reitit/router)
        +(set! s/*explain-out* expound/printer)
        +
        +

        And we are ready to go:

        +
        
        +(reitit/router
        +  ["/api"
        +   ["/public"
        +    ["/ping"]
        +    ["pong"]]])
        +
        +; CompilerException clojure.lang.ExceptionInfo: Call to #'reitit.core/router did not conform to spec:
        +;
        +; -- Spec failed --------------------
        +;
        +; Function arguments
        +;
        +; (["/api" ...])
        +;   ^^^^^^
        +;
        +;     should satisfy
        +;
        +; (clojure.spec.alpha/cat
        +;   :path
        +;   :reitit.spec/path
        +;   :arg
        +;   (clojure.spec.alpha/? :reitit.spec/arg)
        +;   :childs
        +;   (clojure.spec.alpha/*
        +;     (clojure.spec.alpha/and
        +;       (clojure.spec.alpha/nilable :reitit.spec/raw-route))))
        +;
        +; or
        +;
        +; (clojure.spec.alpha/cat
        +;   :path
        +;   :reitit.spec/path
        +;   :arg
        +;   (clojure.spec.alpha/? :reitit.spec/arg)
        +;   :childs
        +;   (clojure.spec.alpha/*
        +;     (clojure.spec.alpha/and
        +;       (clojure.spec.alpha/nilable :reitit.spec/raw-route))))
        +;
        +; -- Relevant specs -------
        +;
        +; :reitit.spec/raw-route:
        +; (clojure.spec.alpha/cat
        +;   :path
        +;   :reitit.spec/path
        +;   :arg
        +;   (clojure.spec.alpha/? :reitit.spec/arg)
        +;   :childs
        +;   (clojure.spec.alpha/*
        +;     (clojure.spec.alpha/and
        +;       (clojure.spec.alpha/nilable :reitit.spec/raw-route))))
        +; :reitit.spec/raw-routes:
        +; (clojure.spec.alpha/or
        +;   :route
        +;   :reitit.spec/raw-route
        +;   :routes
        +;   (clojure.spec.alpha/coll-of :reitit.spec/raw-route :into []))
        +;
        +; -- Spec failed --------------------
        +;
        +; Function arguments
        +;
        +; ([... [... ... ["pong"]]])
        +;                 ^^^^^^
        +;
        +;     should satisfy
        +;
        +; (fn
        +;   [%]
        +;   (or
        +;     (clojure.string/blank? %)
        +;     (clojure.string/starts-with? % "/")))
        +;
        +; or
        +;
        +; (fn
        +;   [%]
        +;   (or
        +;     (clojure.string/blank? %)
        +;     (clojure.string/starts-with? % "/")))
        +;
        +; -- Relevant specs -------
        +;
        +; :reitit.spec/path:
        +; (clojure.spec.alpha/and
        +;   clojure.core/string?
        +;   (clojure.core/fn
        +;     [%]
        +;     (clojure.core/or
        +;       (clojure.string/blank? %)
        +;       (clojure.string/starts-with? % "/"))))
        +; :reitit.spec/raw-route:
        +; (clojure.spec.alpha/cat
        +;   :path
        +;   :reitit.spec/path
        +;   :arg
        +;   (clojure.spec.alpha/? :reitit.spec/arg)
        +;   :childs
        +;   (clojure.spec.alpha/*
        +;     (clojure.spec.alpha/and
        +;       (clojure.spec.alpha/nilable :reitit.spec/raw-route))))
        +; :reitit.spec/raw-routes:
        +; (clojure.spec.alpha/or
        +;   :route
        +;   :reitit.spec/raw-route
        +;   :routes
        +;   (clojure.spec.alpha/coll-of :reitit.spec/raw-route :into []))
        +;
        +; -------------------------
        +; Detected 2 errors
        +
        +

        Validating route data

        +

        TODO

        + + +
        + +
        +
        +
        + +

        results matching ""

        +
          + +
          +
          + +

          No results matching ""

          + +
          +
          +
          + +
          +
          + +
          + + + + + + + + + + + + + + +
          + + +
          + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/basics/different_routers.html b/basics/different_routers.html new file mode 100644 index 00000000..5c9f2615 --- /dev/null +++ b/basics/different_routers.html @@ -0,0 +1,521 @@ + + + + + + + Different Routers · GitBook + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
          +
          + + + + + + + + +
          + +
          + +
          + + + + + + + + +
          +
          + +
          +
          + +
          + +

          Different Routers

          +

          Reitit ships with several different implementations for the Router protocol, originally based on the awesome Pedestal implementation. router selects the most suitable implementation by inspecting the expanded routes. The implementation can be set manually using :router ROUTER OPTION.

          + + + + + + + + + + + + + + + + + + + + + + + + + +
          routerdescription
          :linear-routerMatches the routes one-by-one starting from the top until a match is found. Works with any kind of routes.
          :lookup-routerFastest router, uses hash-lookup to resolve the route. Valid if no paths have path or catch-all parameters.
          :mixed-routerCreates internally a :linear-router and a :lookup-router and used them to effectively get best-of-both-worlds. Valid if there are no CONFLICTING ROUTES.
          :prefix-tree-routerTODO
          +

          The router name can be asked from the router

          +
          (r/router-name router)
          +; :mixed-router
          +
          + + +
          + +
          +
          +
          + +

          results matching ""

          +
            + +
            +
            + +

            No results matching ""

            + +
            +
            +
            + +
            +
            + +
            + + + + + + + + + + + + + + +
            + + +
            + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/basics/index.html b/basics/index.html new file mode 100644 index 00000000..68b11aa1 --- /dev/null +++ b/basics/index.html @@ -0,0 +1,498 @@ + + + + + + + Basics · GitBook + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
            +
            + + + + + + + + +
            + +
            + +
            + + + + + + + + +
            +
            + +
            + +
            +
            + +

            results matching ""

            +
              + +
              +
              + +

              No results matching ""

              + +
              +
              +
              + +
              +
              + +
              + + + + + + + + + + + + + + +
              + + +
              + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/basics/name_based_routing.html b/basics/name_based_routing.html new file mode 100644 index 00000000..df387fd4 --- /dev/null +++ b/basics/name_based_routing.html @@ -0,0 +1,518 @@ + + + + + + + Name-based Routing · GitBook + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
              +
              + + + + + + + + +
              + +
              + +
              + + + + + + + + +
              +
              + +
              +
              + +
              + +

              Name-based routing

              +

              All routes which :name route data defined, can be matched by name.

              +

              Listing all route names:

              +
              (r/route-names router)
              +; [:user/ping :user/user]
              +
              +

              Matching by name:

              +
              (r/match-by-name router ::user)
              +; #PartialMatch{:template "/api/user/:id",
              +;               :meta {:name :user/user},
              +;               :result nil,
              +;               :params nil,
              +;               :required #{:id}}
              +
              +(r/partial-match? (r/match-by-name router ::user))
              +; true
              +
              +

              We only got a partial match as we didn't provide the needed path-parameters. Let's provide the them too:

              +
              (r/match-by-name router ::user {:id "1"})
              +; #Match{:template "/api/user/:id"
              +;        :meta {:name :user/user}
              +;        :path "/api/user/1"
              +;        :result nil
              +;        :params {:id "1"}}
              +
              +

              There is also a exception throwing version:

              +
              (r/match-by-name! router ::user)
              +; ExceptionInfo missing path-params for route /api/user/:id: #{:id}
              +
              + + +
              + +
              +
              +
              + +

              results matching ""

              +
                + +
                +
                + +

                No results matching ""

                + +
                +
                +
                + +
                +
                + +
                + + + + + + + + + + + + + + +
                + + +
                + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/basics/path_based_routing.html b/basics/path_based_routing.html new file mode 100644 index 00000000..1f45b33d --- /dev/null +++ b/basics/path_based_routing.html @@ -0,0 +1,506 @@ + + + + + + + Path-based Routing · GitBook + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                +
                + + + + + + + + +
                + +
                + +
                + + + + + + + + +
                +
                + +
                +
                + +
                + +

                Path-based routing

                +

                Path-based routing is done using the reitit.core/match-by-path function. It takes the router and path as arguments and returns one of the following:

                +
                  +
                • nil, no match
                • +
                • PartialMatch, path matched, missing path-parameters (only in reverse-routing)
                • +
                • Match, exact match
                • +
                +
                (r/match-by-path router "/hello")
                +; nil
                +
                +
                (r/match-by-path router "/api/user/1")
                +; #Match{:template "/api/user/:id"
                +;        :meta {:name :user/user}
                +;        :path "/api/user/1"
                +;        :result nil
                +;        :params {:id "1"}}
                +
                + + +
                + +
                +
                +
                + +

                results matching ""

                +
                  + +
                  +
                  + +

                  No results matching ""

                  + +
                  +
                  +
                  + +
                  +
                  + +
                  + + + + + + + + + + + + + + +
                  + + +
                  + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/basics/route_data.html b/basics/route_data.html new file mode 100644 index 00000000..541ef5ab --- /dev/null +++ b/basics/route_data.html @@ -0,0 +1,531 @@ + + + + + + + Route data · GitBook + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                  +
                  + + + + + + + + +
                  + +
                  + +
                  + + + + + + + + +
                  +
                  + +
                  +
                  + +
                  + +

                  Route data

                  +

                  Routes can have arbitrary meta-data, interpreted by the router (via it's :compile hook) or the application itself. For nested routes, route data is accumulated recursively using meta-merge. By default, it appends collections, but it can be overridden to do :prepend, :replace or :displace.

                  +

                  An example router with nested data:

                  +
                  (def router
                  +  (r/router
                  +    ["/api" {:interceptors [::api]}
                  +     ["/ping" ::ping]
                  +     ["/admin" {:roles #{:admin}}
                  +      ["/users" ::users]
                  +      ["/db" {:interceptors [::db]
                  +              :roles ^:replace #{:db-admin}}
                  +       ["/:db" {:parameters {:db String}}
                  +        ["/drop" ::drop-db]
                  +        ["/stats" ::db-stats]]]]]))
                  +
                  +

                  Resolved route tree:

                  +
                  (reitit/routes router)
                  +; [["/api/ping" {:interceptors [::api]
                  +;                :name ::ping}]
                  +;  ["/api/admin/users" {:interceptors [::api]
                  +;                       :roles #{:admin}
                  +;                       :name ::users}]
                  +;  ["/api/admin/db/:db/drop" {:interceptors [::api ::db]
                  +;                             :roles #{:db-admin}
                  +;                             :parameters {:db String}
                  +;                             :name ::drop-db}]
                  +;  ["/api/admin/db/:db/stats" {:interceptors [::api ::db]
                  +;                              :roles #{:db-admin}
                  +;                              :parameters {:db String}
                  +;                              :name ::db-stats}]]
                  +
                  +

                  Route data is returned with Match and the application can act based on it.

                  +
                  (r/match-by-path router "/api/admin/db/users/drop")
                  +; #Match{:template "/api/admin/db/:db/drop"
                  +;        :meta {:interceptors [::api ::db]
                  +;               :roles #{:db-admin}
                  +;                :parameters {:db String}
                  +;        :name ::drop-db}
                  +;        :result nil
                  +;        :params {:db "users"}
                  +;        :path "/api/admin/db/users/drop"}
                  +
                  + + +
                  + +
                  +
                  +
                  + +

                  results matching ""

                  +
                    + +
                    +
                    + +

                    No results matching ""

                    + +
                    +
                    +
                    + +
                    +
                    + +
                    + + + + + + + + + + + + + + +
                    + + +
                    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/basics/route_syntax.html b/basics/route_syntax.html new file mode 100644 index 00000000..df985965 --- /dev/null +++ b/basics/route_syntax.html @@ -0,0 +1,543 @@ + + + + + + + Route syntax · GitBook + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                    +
                    + + + + + + + + +
                    + +
                    + +
                    + + + + + + + + +
                    +
                    + +
                    +
                    + +
                    + +

                    Route Syntax

                    +

                    Raw routes are defined as vectors, which have a String path, optional (non-sequential) route argument and optional child routes. Routes can be wrapped in vectors and lists and nil routes are ignored. Paths can have path-parameters (:id) or catch-all-parameters (*path).

                    +

                    Simple route:

                    +
                    ["/ping"]
                    +
                    +

                    Two routes:

                    +
                    [["/ping"]
                    + ["/pong"]]
                    +
                    +

                    Routes with route arguments:

                    +
                    [["/ping" ::ping]
                    + ["/pong" {:name ::pong}]]
                    +
                    +

                    Routes with path parameters:

                    +
                    [["/users/:user-id"]
                    + ["/api/:version/ping"]]
                    +
                    +

                    Route with catch-all parameter:

                    +
                    ["/public/*path"]
                    +
                    +

                    Nested routes:

                    +
                    ["/api"
                    + ["/admin" {:middleware [::admin]}
                    +  ["" ::admin]
                    +  ["/db" ::db]]
                    + ["/ping" ::ping]]
                    +
                    +

                    Same routes flattened:

                    +
                    [["/api/admin" {:middleware [::admin], :name ::admin}]
                    + ["/api/admin/db" {:middleware [::admin], :name ::db}]
                    + ["/api/ping" {:name ::ping}]]
                    +
                    +

                    As routes are just data, it's easy to create them programamtically:

                    +
                    (defn cqrs-routes [actions dev-mode?]
                    +  ["/api" {:interceptors [::api ::db]}
                    +   (for [[type interceptor] actions
                    +         :let [path (str "/" (name interceptor))
                    +               method (condp = type
                    +                        :query :get
                    +                        :command :post)]]
                    +     [path {method {:interceptors [interceptor]}}])
                    +   (if dev-mode? ["/dev-tools" ::dev-tools])])
                    +
                    +
                    (cqrs-routes
                    +  [[:query   'get-user]
                    +   [:command 'add-user]
                    +   [:command 'add-order]]
                    +  false)
                    +; ["/api" {:interceptors [::api ::db]}
                    +;  (["/get-user" {:get {:interceptors [get-user]}}]
                    +;   ["/add-user" {:post {:interceptors [add-user]}}]
                    +;   ["/add-order" {:post {:interceptors [add-order]}}])
                    +;  nil]
                    +
                    + + +
                    + +
                    +
                    +
                    + +

                    results matching ""

                    +
                      + +
                      +
                      + +

                      No results matching ""

                      + +
                      +
                      +
                      + +
                      +
                      + +
                      + + + + + + + + + + + + + + +
                      + + +
                      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/basics/router.html b/basics/router.html new file mode 100644 index 00000000..6e2e1958 --- /dev/null +++ b/basics/router.html @@ -0,0 +1,514 @@ + + + + + + + Router · GitBook + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                      +
                      + + + + + + + + +
                      + +
                      + +
                      + + + + + + + + +
                      +
                      + +
                      +
                      + +
                      + +

                      Router

                      +

                      Routes are just data and to do actual routing, we need a Router satisfying the reitit.core/Router protocol. Routers are created with reitit.core/router function, taking the raw routes and optionally an options map. Raw routes gets expanded and optionally coerced and compiled.

                      +

                      Router protocol:

                      +
                      (defprotocol Router
                      +  (router-name [this])
                      +  (routes [this])
                      +  (options [this])
                      +  (route-names [this])
                      +  (match-by-path [this path])
                      +  (match-by-name [this name] [this name params]))
                      +
                      +

                      Creating a router:

                      +
                      (require '[reitit.core :as r])
                      +
                      +(def router
                      +  (r/router
                      +    [["/api"
                      +      ["/ping" ::ping]
                      +      ["/user/:id" ::user]]]))
                      +
                      +

                      Router flattens the raw routes and expands the route arguments using reitit.core/Expand protocol. By default, Keywords are expanded to :name and functions are expaned to :handler. nil routes are removed. The expanded routes can be retrieved with router:

                      +
                      (r/routes router)
                      +; [["/api/ping" {:name :user/ping}]
                      +;  ["/api/user/:id" {:name :user/user}]]
                      +
                      + + +
                      + +
                      +
                      +
                      + +

                      results matching ""

                      +
                        + +
                        +
                        + +

                        No results matching ""

                        + +
                        +
                        +
                        + +
                        +
                        + +
                        + + + + + + + + + + + + + + +
                        + + +
                        + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/index.html b/index.html index 65f44e12..0d87772d 100644 --- a/index.html +++ b/index.html @@ -57,6 +57,8 @@ + + @@ -98,23 +100,23 @@ -
                      • +
                      • - + Basics - +