Skip to content

Commit 5d07819

Browse files
committed
First commit.
0 parents  commit 5d07819

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
lines changed

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 StaticWeb.io
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# clj-http-failjure

deps.edn

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

src/clj_http_failjure/client.clj

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
(ns clj-http-failjure.client
2+
(:require [clj-http.client :as client]
3+
[clj-http.util :as util]
4+
[failjure.core :as f])
5+
(:refer-clojure :exclude [get]))
6+
7+
; From https://github.com/dakrone/clj-http/blob/aee13b4f544e83e4eb6014d6d1f9178676899f13/src/clj_http/client.clj#L1158-L1165
8+
(defn- request*
9+
[req [respond raise]]
10+
(if (util/opt req :async)
11+
(if (some nil? [respond raise])
12+
(throw (IllegalArgumentException.
13+
"If :async? is true, you must pass respond and raise"))
14+
(client/request (dissoc req :respond :raise) respond raise))
15+
(client/request req)))
16+
17+
(defmacro def-request-method [method-symbol]
18+
`(defn ~method-symbol
19+
"Like #'request, but sets the :method and :url as appropriate."
20+
[~'url & [~'req & ~'r]]
21+
(client/check-url! ~'url)
22+
(let [~'req (merge ~'req {:method ~(keyword method-symbol)
23+
:url ~'url})]
24+
(f/try*
25+
(request* ~'req ~'r)))))
26+
27+
(def-request-method get)
28+
(def-request-method head)
29+
(def-request-method post)
30+
(def-request-method put)
31+
(def-request-method delete)
32+
(def-request-method options)
33+
(def-request-method copy)
34+
(def-request-method move)
35+
(def-request-method patch)

0 commit comments

Comments
 (0)