Coder Social home page Coder Social logo

paraman's Introduction

paraman

Clojars Project

Paraman is a Clojure library for converting Clojure maps into valid HTTP query params. It supports arrays and nested objects.

I saw the need for such a library because I found out both clj-http and http-kit clients do not fully support both arrays, nested objects or arrays consisting of objects, which some API require (For example, Stripe API).

Usage

Instead of passing your params map to either clj-http or http-kit :form-params request option, use the library to convert your params into a valid HTTP query string and pass it directly to the request :body of either your clj-http or http-kit request options. Instead of:

(require '[org.httpkit.client :as http])
(def my-post-data {:some [{:obj "key1"} {:obj "key2"}]})
@(http/post "http://some.url.com/resource" {:form-params my-post-data})
; =>  java.lang.ClassCastException: clojure.lang.PersistentArrayMap cannot be cast to clojure.lang.Named

Do:

(require '[org.httpkit.client :as http])
(require '[paraman.core :refer [convert]])
(def my-post-data {:some [{:obj "key1"} {:obj "key2"}]})
@(http/post "http://some.url.com/resource" {:body (convert my-post-data)})

And you're good to go. Your map will be converted to valid HTTP encoded form params.

License

Copyright © 2016 FIXME

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

paraman's People

Contributors

erez-rabih avatar camsaul avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.