Comments (9)
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.
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.
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.
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.
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.
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.
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.
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.
That's something I'll work on, I'll open a separate issue to track it.
from clj-http.
Related Issues (20)
- Async HTTP Request Connection Timeout Not Work Correctly HOT 3
- The word 'officially' is spelt wrong in the GitHub description HOT 1
- HEAD requests shouldn't discard body (in the request).
- Handling of private proxies HOT 2
- Whenever I get a 405 response from a server, a null pointer exception is thrown because the connection wasn't found HOT 1
- Nested query params
- cookie-policy none
- URL encoding of whitespace should be "%20" instead of "+" in query parameters HOT 1
- Calling `.close` on response http stream will fully read stream contents rather than terminating. HOT 2
- `:query-params` are re-ordered
- :threads is mis-named and mis-documented
- multipart posts: sending name requires a mime-type
- Async requests not really async
- AOT issues with clj_http.headers.HeaderMap HOT 4
- url path parameters HOT 2
- The :redirect-strategy doesn't seem to work for PUT and PATCH HTTP methods
- option to pre-process `:query-params` HOT 1
- Retry when service is (tempoarily) unavailable HOT 3
- `with-middleware` rebinds `http/request` with new core client
- Support async with socks proxy?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clj-http.