A Clojure library designed to convert ring requests into cURL commands.
It's main purpose is in debugging applications, as it easily allows you to replay requests against services.
ring-curl
is available as a Maven artifact from Clojars.
Note: v1.0.0 is broken on Clojars, see issue #4 for more details.
(:require [ring-curl.core :as ring-curl])
(ring-curl/to-curl request)
; or with options
(ring-curl/to-curl request {:some-option "the-value"})
The following options can be used to modify the output, see the cURL man page for more details about exactly what each option will do.
-
:verbose?
Atruthy
value adds the-v
curl flag to the output. -
:very-silent?
Atruthy
value adds the-s
curl flag to the output. -
:silent?
Atruthy
value adds the-s
and-S
curl flags to the output. -
:no-proxy
Asequence
ofstrings
will add the--noproxy "<vals>"
curl flag to the output. -
:progress-bar?
Atruthy
value adds the-#
curl flag to the output. -
:insecure?
Atruthy
value adds the-k
curl flag to the output. -
:connect-timeout
Ainteger
value adds the--connect-timeout <val>
curl flag to the output. -
:max-time
Ainteger
value adds the-m <val>
curl flag to the output. -
:no-buffer?
Atruthy
value adds the-N
curl flag to the output. -
:output
Astring
value adds the-o "<val>"
and--create-dirs
curl flags to the output. -
:retry
Ainterger
value adds the--retry <val>
curl flag to the output. -
:dump-headers
Astring
value adds the-D "<val>"
curl flag to the output.
There is middleware included to automatically log every request as curl. This middleware should be the last middleware in the chain, this will ensure the request has been properly modified by all the other middleware.
(require [ring-curl.middleware :refer :all])
(defn handler [request]
(response {:foo "bar"}))
(def app
(wrap-curl-logging handler))
You can replace the xml and json writers with your own by binding:
(:require [ring-curl.core :as ring-curl])
(binding [ring-curl/write-json my-custom-function]
(ring-curl/to-curl request))
(binding [ring-curl/write-xml my-custom-function]
(ring-curl/to-curl request))
If you use clj-http you can use the convert
function under the ring-curl.clj-http
namespace to convert it to a ring request. This will allow it to be printed correctly as curl by the core
namespace.
If you would like to add a feature/fix a bug for us please create a pull request. Be sure to include or update any tests if you want your pull request accepted.
Copyright © 2014 - 2018 Christopher Martin
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.