前言

Emacs 中的 restclient 已经归档了不在维护,所以就需要找一下其它的包来代替。

找了一圈发现 federicotdn/verb: HTTP client for Emacs 还不错,并且也支持 org babel

安装

1
2
3
(use-package verb
  :init (cl-pushnew '(verb . t) load-language-list)
  :config (define-key org-mode-map (kbd "C-c C-r") verb-command-map))

使用

verb 支持两种方式,第一种是在 Org Mode 中给 Headl 加上 verb 的 tag

1
2
3
* Http request :verb:
  get https://httpbin.org/get
  Accept: application/json

注意使用这个方式不能有缩进,我试了好久才发现,不然使用 x-www-form-urlencoded 会有问题

第二种是使用 org babel

1
2
3
4
#+begin_src verb
get https://httpbin.org/get
Accept: application/json
#+end_src

执行后得到响应如下所示

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
HTTP/1.1 200 OK
Date: Mon, 24 Mar 2025 12:52:51 GMT
Content-Type: application/json
Content-Length: 293
Connection: keep-alive
Server: gunicorn/19.9.0
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true

{
  "args": {},
  "headers": {
    "Accept": "application/json",
    "Accept-Encoding": "gzip",
    "Host": "httpbin.org",
    "Mime-Version": "1.0",
    "X-Amzn-Trace-Id": "Root=1-67e155a1-19b45d090d39dd3a02fe2b2c"
  },
  "origin": "...",
  "url": "https://httpbin.org/get"
}

导出

verb 还有一点功能非常吸引我的就是支持导出,导出到 curl 如下所示

1
2
3
#+begin_src verb :op export curl

#+end_src

总结

verb 用起来和 restclient 差不多,没有什么切换成本,而且还支持导出,还是一个不错的选择。

参考

federicotdn/verb: HTTP client for Emacs