Code Monkey home page Code Monkey logo

Comments (9)

michaelklishin avatar michaelklishin commented on July 17, 2024

I don't see form params being used in the original pull request you are referring to. So when :content-type is set to :json, body params will be serialized to JSON, otherwise as query string.

What exactly does "properly" mean here?

from clj-http.

michaelklishin avatar michaelklishin commented on July 17, 2024

And as a side note, if you are working on a Neo4J Server REST API client, there is at least one already. Gremlin support probably can be just added to it.

from clj-http.

michaelklishin avatar michaelklishin commented on July 17, 2024

I seem to be wrong. After looking at the source in master, I see this

(defn wrap-form-params [client]
  (fn [{:keys [form-params content-type request-method]
        :or {content-type :x-www-form-urlencoded}
        :as req}]
    (if (and form-params (#{:post :put} request-method))
      (client (-> req
                  (dissoc :form-params)
                  (assoc :content-type (content-type-value content-type)
                         :body (if (and (= content-type :json) json-enabled?)
                                 (json-encode form-params)
                                 (generate-query-string form-params)))))
      (client req))))

where json-enabled? checks for Cheshire (which is now an optional dependency, as far as I remember) being present:

(def json-enabled?
  (try
    (require 'cheshire.core)
    true
    (catch Throwable _
      false)))

But you seem to have it, if it works for :params. This change is the only recent change I could find that may affect :form-params handling.

Or I just don't understand what is expected.

from clj-http.

espeed avatar espeed commented on July 17, 2024

Hi Michael -

Actually, neither one of my examples work with Neo4j Server -- I was playing around with netcat and overlooked the fact that it shouldn't be encoding the string:

"{"params":{"id":321},"script":"g.v(id)"}"

However, the structure is right, whereas the structure in the second example is not:

{"params[id]":321,"script":"g.v(id)"}

Notice that the params variable is params[id]:321 instead of params: {"id": 321}.

from clj-http.

michaelklishin avatar michaelklishin commented on July 17, 2024

The way it works is this. For POST and PUT requests

  • if :content-type is set to :json and Cheshire is loaded, clj-http will serialize form-params and body to JSON
  • otherwise, form-params are encoded as query string

In the 2nd example, the structure is what it should be for query string serialization. I also see that you manually serialize params to JSON. So I suspect there is double encoding going on.

Neocons uses clj-http and support almost all Neo4J Server features. However, I do not use Cheshire for JSON serialization and automatic serialization is not used.

from clj-http.

espeed avatar espeed commented on July 17, 2024

Thanks Michael. I switched to manually encoding and setting the JSON string in body rather than going through the autoencoding form-params mechanism -- it works now.

I'm porting Bulbs (http://bulbflow.com) to Clojure to learn the language. As my Clojure fu improves, I'll go back to see why the form-params thing isn't working.

from clj-http.

dakrone avatar dakrone commented on July 17, 2024

I've fixed it in 2e5aab8.

It was an issue with nested form param handling running when it shouldn't for json encoding.

from clj-http.

espeed avatar espeed commented on July 17, 2024

Thanks Lee. Is there a way to display the JSON params in the debug output?

Right now it's showing up as...

:body #<StringEntity org.apache.http.entity.StringEntity@790a367f>

...which makes it difficult to debug.

from clj-http.

dakrone avatar dakrone commented on July 17, 2024

That's something I'll work on, I'll open a separate issue to track it.

from clj-http.

Related Issues (20)

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.