Restclient.el for Emacs

by Noah Frederick |

The restclient.el package provides a REPL-like interface for HTTP requests, which is particularly useful for exploring REST APIs. See the Emacs Rocks! episode to get an idea of what it can do. Each of the requests you include in a restclient buffer can be executed individually, and doing so opens a window with the response headers and body with JSON or XML syntax highlighting as appropriate:

:api-url = http://localhost:8000/api
:secret-key := (read-string "Secret key: ")

#
# List records
#
GET :api-url/users
secretKey: :secret-key

#
# Create new record
#
PUT :api-url/users
secretKey: :secret-key
Content-Type: application/json
{
  "id": 9999,
  "foo": "bar"
}

#
# Update record
#
POST :api-url/users/9999
secretKey: :secret-key
Content-Type: application/json
{
  "foo": "baz"
}

You can, of course, save your buffer to a file, so it can be handy to associate the restclient-mode with a file extention (e.g., .http), which can be accomplished with the following, assuming you are taking advantage of use-package:

(use-package restclient
  :mode ("\\.http\\'" . restclient-mode))