-
Notifications
You must be signed in to change notification settings - Fork 172
Feature request: save body of GET result to file #275
Comments
I can possibly borrow code from some of the examples in #149 ? But it would be nice to have a simpler way do do things. And it would be nice to have the handling located in the query, instead of having to add a hook, and test for the url in the hook. |
I thought something similar to this, in my .emacs, could do the trick:
And use it like this:
But it fails because the HTTP response buffer can't be found (race condition?):
Also, I can't borrow restclient-jq-result-end-point to find the end of the response, because a GET response looks like this:
I would have liked to save everything from "sha256" and up to, and including, the final "Y" (i.e. not save the line shift). |
I've made this work, with a little help from the help-gnu-emacs mailing list. The first enlightenment I had was that the evaluation result of restclient-jq-json-var-function was a lambda. The second enlightenment, was that I learned about emacs lisp lexical scope. I tried returning a lambda from the hook function, with the following content in ~/.emacs:
But that didn't work, and I eventually figured out that this was because filename was undefined when the lambda was executed. However I could see restclient-jq-json-var-function do the very thing I was trying to do: define a variable in a let clause, and use that variable in a lambda. So I asked on the help-gnu-emacs mailing list, and was told that I needed to add a magical cookie to the file to get lexical scoping. So I created a file called sb-restclient.el in a directory in the load-path, with the following content:
and in my ~/.emacs put the following:
A little to my surprise, restclient-jq-result-end-point worked on emacs 27 on Windows and on debian GNU/linux, because in both places, the headers of a GET response were prefixed with "//". But on emacs 27 on mac I needed to write a different function to find the end of the body, because there the HTTP headers in the response were not prefixed with "//" (as shown in the previous comment). |
The sb-restclient.el file on mac looks like this
I haven't tested, but this will probably work for a GET on non-macs as well. However, the version that uses restclient-jq-result-end-point, works on all methods, not just GET. No idea why the GET response on mac is different from the POST response. emacs-version on the mac reports: GNU Emacs 27.1 (build 1, x86_64-apple-darwin18.7.0, NS appkit-1671.60 Version 10.14.6 (Build 18G95)) of 2020-08-12 The restclient.el version is the current git master HEAD. |
I need to do a GET with basic auth to get a token.
The body of the GET response is the token.
I would like to save that body to a file, and I haven't found a way to do this.
I had hoped that "> ~/.authToken" in the body would do the trick, similar to how a body can be fetched from a file.
But that didn't work.
It's also possible that "->" with some lisp code, could do the trick, but I looked at restclient-jq-json-var-function and I wasn't able to figure out where/how the body enters the function.
The text was updated successfully, but these errors were encountered: