(any-handler {:keys [route] :as opts})invokes function when request matches route
((any-handler {:route "/hello" :fn (fn [req] {:status :return})}) {:route "/hello"}) => {:status :return}
invokes function when request matches route
((any-handler {:route "/hello"
:fn (fn [req] {:status :return})})
{:route "/hello"})
=> {:status :return}(endpoint-handler {:keys [route functions format] :as opts :or {format :edn}})constructs a endpoint handler
(-> ((endpoint-handler {:route "/app" :functions {:add (fn [a b] (+ a b))}}) {:route "/app" :body (str {:id :add :args [1 2]})}) :body read-string) => (contains {:id :add, :status :return, :data 3})
constructs a endpoint handler
(-> ((endpoint-handler {:route "/app"
:functions {:add (fn [a b] (+ a b))}})
{:route "/app"
:body (str {:id :add
:args [1 2]})})
:body
read-string)
=> (contains {:id :add, :status :return, :data 3})(endpoint-handler-apply functions id args)applies arguments to the handler
(endpoint-handler-apply {:add (fn [a b] (+ a b))} :add [1 2]) => (contains {:data 3, :id :add})
applies arguments to the handler
(endpoint-handler-apply {:add (fn [a b] (+ a b))}
:add
[1 2])
=> (contains {:data 3, :id :add})(match-route {:keys [method route] :as opts} req)matches route for handler and request
(match-route {:method :get :route "hello"} {:method :get :route "hello"}) => true
matches route for handler and request
(match-route {:method :get
:route "hello"}
{:method :get
:route "hello"})
=> true(method-handler {:keys [type] :as opts})invokes function when request matches route and method
((method-handler {:method :get :route "/hello" :fn (fn [req] {:status :return})}) {:method :get :route "/hello"}) => {:status :return}
invokes function when request matches route and method
((method-handler {:method :get
:route "/hello"
:fn (fn [req] {:status :return})})
{:method :get
:route "/hello"})
=> {:status :return}(multi-handler routes)chains multiple handlers together
((multi-handler [(method-handler {:method :get :fn (constantly {:status :get})}) (any-handler {:fn (constantly {:status :any})})]) {:method :post}) => {:status :any}
chains multiple handlers together
((multi-handler [(method-handler {:method :get
:fn (constantly {:status :get})})
(any-handler {:fn (constantly {:status :any})})])
{:method :post})
=> {:status :any}(resource-handler {:keys [route root] :as opts})returns a file on the resource path
((resource-handler {:route "/resource"}) {:method :get :route "/resource/project.clj"}) => (contains {:status 200})
returns a file on the resource path
((resource-handler {:route "/resource"})
{:method :get
:route "/resource/project.clj"})
=> (contains {:status 200})(trim-seperators s)gets rid of seperators on ends of string
(trim-seperators "//api/me//") => "api/me"
gets rid of seperators on ends of string (trim-seperators "//api/me//") => "api/me"
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |