tkf / emacs-request

Request.el -- Easy HTTP request for Emacs Lisp
http://tkf.github.com/emacs-request/
GNU General Public License v3.0
629 stars 93 forks source link

Parameter (params) with special characters do not work #189

Closed dangom closed 4 years ago

dangom commented 4 years ago

If I set params to ("filter[stop]" . "North+Station"), then the characters [ and ] get hexified and the request fails. Is there a way to temporarily allow these characters in a let form?

Example:

(request
         "https://api-v3.mbta.com/schedules"
         :params '(("filter[stop]" . "North+Station") ;; this is not going to work.
                   ("sort" . "arrival_time")
                   ("filter[min_time]" . "18:00"))
         :parser 'json-read
         :success (function*
                   (lambda (&key data &allow-other-keys)
                     (let* ((item (elt (assoc-default 'items data) 0))
                            (title (assoc-default 'title item))
                            (tags (assoc-default 'tags item)))
                       (message "%s %S" title tags)))))
dickmao commented 4 years ago
(request--urlencode-alist '(("filter[stop]" 
. "North+Station")))

So your goal is to avoid yielding "filter%5Bstop%5D=North%2BStation"

I cannot currently reconcile your goal with this SO reply suggesting such special characters need to be hexified.

https://stackoverflow.com/questions/1455578/characters-allowed-in-get-parameter

dangom commented 4 years ago

Thanks for the quick reply. Trying to translate the following call to request.el:

https://api-v3.mbta.com/schedules?filter[stop]=North+Station&filter[direction_id]=0&filter[min_time]=18:00&sort=-arrival_time

dickmao commented 4 years ago
(let (result) 
  (request 
    "https://api-v3.mbta.com/schedules" :params '(("filter[stop]" 
    . "North Station") 
              ("filter[direction_id]" . "0") ("sort" 
              . "-arrival_time") ("filter[min_time]" . "18:00")) 
    :sync t :parser 'json-read :success (cl-function 
              (lambda (&key data &allow-other-keys) 
                (setq result 
                      (mapcar (lambda (x) (alist-get 'id (append x 
                      nil))) 
                              (alist-get 'data data)))))) 
  result)