reddit / emacs

Varibles Aren't Working With Restclient

tompurl · 2022-05-26 20:35
I'm learning how to use `restclient` and I'm attempting the following list of simplet requests: ``` # -*- restclient -*- POST https://restful-booker.herokuapp.com/auth Content-Type: application/json -> jq-set-var :token .token { "username" : "admin", "password" : "password123" } ### POST https://restful-booker.herokuapp.com/booking Content-Type: application/json -> jq-set-var :bookingid .bookingid { "firstname": "Jesus", "lastname": "Ramirez", "totalprice": 345, "depositpaid": true, "bookingdates": { "checkin": "2022-07-01", "checkout": "2022-07-14" }, "additionalneeds": "Lunch" } ### DELETE https://restful-booker.herokuapp.com/booking/:bookingid Content-Type: application/json Cookie: token=:token ``` I execute the first two requests using `C-c C-c` and get the expected JSON results. However, when I execute the third request (which uses variables created by the first two requests) I get the following message: ``` Forbidden DELETE https://restful-booker.herokuapp.com/booking/:bookingid HTTP/1.1 403 Forbidden Server: Cowboy Connection: keep-alive X-Powered-By: Express Content-Type: text/plain; charset=utf-8 Content-Length: 9 Etag: W/"9-PatfYBLj4Um1qTm5zrukoLhNyPU" Date: Thu, 26 May 2022 20:33:01 GMT Via: 1.1 vegur Request duration: 0.102513s ``` The first thing I notice is that `:bookingid` doesn't seem to expand in the second line. Does anyone know what I'm missing when using `jq-set-var`?
whudwl · 2022-05-26 22:29
You might need to `(require 'restclient-jq)` before you can use `jq-set-var`. And if the var is set successfully, you should see a message saying so. For example, when I execute this request GET http://httpbin.org/ip -> jq-set-var :my-var .origin There would be these messages HTTP GET http://httpbin.org/ip Headers:[nil] Body:[] Contacting host: httpbin.org:80 restclient var [:my-var = "xxx.xxx.xxx.xxx"]
tompurl · 2022-06-01 21:36
Thank you for the suggestion @whudwl. I didn't know I was supposed to see that. I tried what you said and I am seeing this message now: ``` Unknown restclient hook type jq-set-var ``` I've confirmed that I have all of the latest versions of all of the requirements. I therefore opened the following Github issue: - https://github.com/pashky/restclient.el/issues/282 Thanks again!
whudwl · 2022-06-02 01:43
>Unknown restclient hook type jq-set-var means `restclient-jq` is not available. have you tried `(require 'restclient-jq)` ?