Skip to content

Clojure curl implementation #117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
practicalli-johnny opened this issue Feb 12, 2023 · 1 comment
Open

Clojure curl implementation #117

practicalli-johnny opened this issue Feb 12, 2023 · 1 comment
Labels

Comments

@practicalli-johnny
Copy link
Contributor

No description provided.

@practicalli-johnny
Copy link
Contributor Author

Using clj-http library to create a clojure curl style command

TODO: can this be re-implmented with http-kit/client ?

(ns foo
  (:require [clj-http.client :as client]
            [clj-http.headers :as headers]))

(defn request [req]
  (client/with-middleware [headers/wrap-header-map
                           client/wrap-query-params
                           client/wrap-url
                           client/wrap-output-coercion
                           client/wrap-method]
    (client/request req)))

;; `:keys` included for documentation
(defn curl [method url & {:keys [headers query-params] :as req}]
  (request (merge req {:method method :url url})))

;; curl -X POST --header "Content-Type: application/json" -d "name=Bob" "http://google.com"
(curl :post "http://google.com" :headers {"Content-Type" "application/json"} :query-params {"name" "Bob"})

To send the request as a body

(curl :post "http://google.com" :headers {"Content-Type" "application/json"} :body '{"name" "Bob"}')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: No status
Development

No branches or pull requests

1 participant