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?Atruthyvalue adds the-vcurl flag to the output. -
:very-silent?Atruthyvalue adds the-scurl flag to the output. -
:silent?Atruthyvalue adds the-sand-Scurl flags to the output. -
:no-proxyAsequenceofstringswill add the--noproxy "<vals>"curl flag to the output. -
:progress-bar?Atruthyvalue adds the-#curl flag to the output. -
:insecure?Atruthyvalue adds the-kcurl flag to the output. -
:connect-timeoutAintegervalue adds the--connect-timeout <val>curl flag to the output. -
:max-timeAintegervalue adds the-m <val>curl flag to the output. -
:no-buffer?Atruthyvalue adds the-Ncurl flag to the output. -
:outputAstringvalue adds the-o "<val>"and--create-dirscurl flags to the output. -
:retryAintergervalue adds the--retry <val>curl flag to the output. -
:dump-headersAstringvalue 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.