hi I am new to clojure, and I got a question I have not being able to find a definitive answer on google I work with a big java desktop application, where I have managed to embedd jython to provide a scripting framework it works well, but I hate java scientific libraries, jython cannot use numpy and Co. I got interested in Inchanter instead. Now I am wondering if I can also embedd clojure into the java app in the same way as I did for jython. What I do with jython, is on java, I create an interpreter, set paths to different modules I need dynamically then I put a 2D matrix (a list of lists) into the interpreter and then I load the script I want and execute a function that will always be in every script by convention, and which takes that 2D matrix I put into the interpreter the function returns another 2D matrix, which then I can recover from java side and cast to java types and then some other small things like redirecting jython stdout and stderr to java so that I can print nicely on the java app, etc Would it be possible with clojure? Somehow I got the feeling it is not designed for this purpose.
@sidrero: http://clojure.org/java_interop#Java%20Interop-Calling%20Clojure%20From%20Java
Hi @sidrero you should be able to use core.matrix for most of what you need. It supports conversions to / from various different matrix representations
core.matrix is roughly equivalent to numpy in terms of scope, most of the same functionality is there too
I have a small question regarding clj-http. How can I emulate a curl post that does this? curl -X POST 'https://website.com/endpoint' -d 'request_body={ ... }'
@nnbosko: this should do it
(require '[cheshire.core :as json])
(require '[clj-http.client :as http])
(http/post "<https://website.com/endpoint>" {:body (json/encode {...})})
there are a lot of excellent examples in the readme on github https://github.com/dakrone/clj-httpSorry, I should have been more specific. The issue isn't that per se, I know more or less how to deal with clj-http, the issue is specifically sending 'request_body = { ... }' as data
Not request body as a json parameter itself, but request_body={ "api_key" : "xxxxxx", "name" : "xxxxx" etc }
hence -d 'request_body={...}'
Am I clear, @oliy?
so the body is "request_body={...}"?
I wouldn't say that, because doing (http/post "website" {:body "request_body={...}"}) fails
then i'm afraid the finer points of what curl is doing there is lost on me!
@nnbosko: "I wouldn't say that, because doing (http/post "website" {:body "request_body={...}"}) fails" fails how?
It says request_body is empty
More specifically this is the body of the request I'm getting from the server
:body "{\"status\":\"ERROR\",\"status_code\":\"BP-DPAR-1\",\"status_message\":\"request_body is empty\"}"
I think it's something on your server side. I tried here and (client/post "<http://localhost:5000>" {:body "request_body={...}"})
works fine, the server gets the string "request_body={...}"
what’s the content-type header on the POST?
typically you need to set application/x-www-form-urlencoded
to get standard parsing behaviors to work, this is often automatic
yeah, if it works with curl but doesn't work with clj-http, it's probably a matter of the default content-type being different for each one, which causes the server to misunderstand the body