Liking cljdoc? Tell your friends :D

hara.net.http.handler


any-handlerclj

(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}
raw docstring

endpoint-handlerclj

(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})
raw docstring

endpoint-handler-applyclj

(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})
raw docstring

match-handlerclj


match-routeclj

(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
raw docstring

method-handlerclj

(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}
raw docstring

multi-handlerclj

(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}
raw docstring

resource-handlerclj

(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})
raw docstring

trim-seperatorsclj

(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"
raw docstring

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

× close