freenode/#lisp - IRC Chatlog
Search
1:04:03
pillton
Xach: Is that something that is automatically done or do you have to manually do it?
4:15:36
dwts
hey guys, doing something like this: curl http://api.urbandictionary.com/v0/define?term={nuts} I'm getting a json output. I'm trying to perform the same results with drakma. But drakma complains about illegal characters(curly brackets)
4:17:53
Bike
with drakma you give ti the GET parameters separately and not as part of the url, maybe
4:22:06
dwts
Bike: hmmm...the drakma documentation says to use this kind of syntax: (drakma:http-request "http://lisp.org/") . Can't find it documented either the separate GET parameters
4:49:48
loke`
dwts: The full parameter documentation for drakma is in the docstring for HTTP-REQUEST
4:51:29
dwts
loke`: thanks! is there an easy way to access to that docstring directly through emacs?
5:01:31
dwts
loke`: I'm trying something different. (defparameter *k* (drakma:url-encode "http://api.urbandictionary.com/v0/define?term={nuts}" :utf-8)) Then this: (drakma:http-request *k* :method :get)
5:02:27
loke`
I'm guessing you have read the API documentation, where the curlies are there to indicate that this is where you put your own text.
5:02:54
loke`
secondly, in order to have all the URL encoding working correctly, you should use the :PARAMETERS argument:
5:03:08
loke`
(drakma:http-request "http://api.urbandictionary.com/v0/define" :parameters '(("term" . "nuts")))
5:03:16
resttime
If you don't mind some newer libs check out dexador: https://github.com/fukamachi/dexador
5:03:35
resttime
Outputs -> "{\"tags\":[],\"result_type\":\"no_results\",\"list\":[],\"sounds\":[]}"
5:03:55
loke`
resttime: His problem si that he's passing the curlies. Even if he encodes them correctly he'll get an error message tfrom the remote server
5:07:02
resttime
dwts: You're trying to use what I suppose is curl syntax with other things, this wouldn't even work if you used like Python or something
5:08:10
dwts
while what loke` suggested get's executed successfully(drakma http-request), I still don't see the json output
5:11:41
loke`
dwts: It's returned as binary data. You can eiter convert it using something libe (babel:octests-to-string ... :encoding :urf-8)
5:14:50
loke`
The drakma documentation says: ”If the message body doesn't have a text content type or if FORCE-BINARY is true, the body is always returned as an array of octets.”
5:15:20
loke`
The request you make returns application/json, which is why it's returned as a binary vector and not a string.
5:16:33
loke`
dwts: You probably want to pass the decoded output to something like ‘st-json’ or one of the other JSON libraries.
5:17:10
resttime
Ah here we go, I recall something that's nice. If you want drakma to convert to text automatically: (push (cons "application" "json") drakma:*text-content-types*)
5:17:20
loke`
You should do something like (babel:octets-to-string (drakma:http-request ...) :encoding :utf-8)
5:18:31
loke`
dwts: I'm not debugging anything. I know drakma pretty well (even though I missed the part about *TEXT-CONTENT-TYPES*)
5:19:16
resttime
dwts, loke`. Just remembered running into it some time before couldn't recall top of head but a good old google helps all the time :)
5:20:01
dwts
loke`: yeah, takes some time to get used to the output. there's enough info there I guess, now I noticed the full message: (:CONTENT-TYPE . "application/json; charset=utf-8")
5:20:11
loke`
resttime: In 99% of cases, I use :WANT-STREAM, and just wrap it in a flexi-stream to do the parsing anyway.
5:21:09
loke`
I guess that the *TEXT-CONTENT-TYPES* has the benefit of parsing the ;charset= parameter for you... In case you meet a server that is insane enough to give you JSON with a non-utf-8 encoding. :-)
5:37:27
resttime
nginx proxy server to https://github.com/fukamachi/woo -> with https://github.com/fukamachi/ningle
6:02:22
resttime
(dex:get "https://google.com" :stream t :insecure t) Something like that should be making a new stream with the right flags I think
6:14:29
resttime
Yeah there we go recent commit too: https://github.com/fukamachi/dexador/commit/0b0e0b56f9c695d052a46c85f9e20f6e30946526#diff-94c10f296dac06851e39cc9ad5773f9b
6:36:48
loke`
The onyl way I can get around this, it seems, is by getting the cert used for signing and add that manually.
6:56:29
resttime
https://github.com/fukamachi/dexador/commit/0b0e0b56f9c695d052a46c85f9e20f6e30946526#diff-94c10f296dac06851e39cc9ad5773f9b
8:12:19
Shinmera
Dexador is nicely fast (drakma is dog slow), but I've had some issues with it just erroring over simple stuff
8:12:32
Shinmera
Don't remember the context of the breakage, but it wasn't even anything about cl+ssl.