1

I am trying to use request.el to make a simple post request in elisp to my API, running on localhost. Here is the request in restclient.el format that I am trying to make in elisp using request.el:

POST https://localhost/action/loginAuthenticate
Content-Type: application/json

{  
    "data":
    {
        "username": "usernamehere",
        "password": "passwordhere"
    }
}

Here is my attempt at making the request in elisp, using the documentation from https://github.com/tkf/emacs-request :

(require 'json)
(require 'request)
(setf debug-on-error t)
(request
    "https://localhost/action/loginAuthenticate"
    :type "POST"
    :headers '(("Content-Type" . "application/json"))
    :data (json-encode '(("data" ("username" . "usernamehere") ("password" . "passwordhere"))))
    :parser 'json-read
    :success (cl-function
        (lambda (&key data &allow-other-keys)
        (message "Response is: %S" (request-response-data response)))))

I'm getting the following error message when using M-x eval-buffer to evaluate my elisp code:

[error] request-default-error-callback: https://localhost/action/loginAuthenticate parse-error

I'm not sure what is causing this error. In addition, even though I've included the form (setf debug-on-error t) and have also tried executing M-x toggle-debug-on-error, I'm not getting any additional debug output in any emacs buffers. (I'm guessing the debug information is limited to the one line error message).

Finally, It's worth mentioning that the request is not making it to my API, which tells me the problem has to do with my code above.

What am I doing wrong here?

Drew
  • 29,895
  • 7
  • 74
  • 104
TheDarkHoarse
  • 416
  • 4
  • 9
  • Please do not use tag `elisp` for questions about how to use Elisp. https://emacs.stackexchange.com/tags/elisp/info. – Drew May 16 '20 at 14:59
  • I am not sure but I feel I had a similar problem. It turns out I did not really understand the request.el library (I feel that is for a large part due to its documentation btw). Anyway, in my case part of the solution was to add `:sync t` to the keyword arguments. Additionally, I suggest you remove `:parser 'json-read` and the `:succes` part, and study the object `(request ...)` returns. Subsequently you might want to use the returned object as an argument to `request-response-data`. At least that is what I am doing now with my primitive understanding of lisp. Anyway... try the `:sync t` part. – dalanicolai Jul 06 '20 at 11:39

0 Answers0