restclient

https://github.com/pashky/restclient.el.git

git clone 'git://github.com/pashky/restclient.el.git'
373

restclient.el

This is a tool to manually explore and test HTTP REST webservices. Runs queries from a plain-text query sheet, displays results as a pretty-printed XML, JSON and even images.

Usage

You can easily install restclient using package.el from MELPA.

Alternatively, deploy restclient.el into your site-lisp as usual, then add (require 'restclient) to your Emacs start-up file.

Once installed, you can prepare a text file with queries.

restclient-mode is a major mode which does a bit of highlighting and supports a few additional keypresses:

Query file example:

# -*- restclient -*-
#
# Gets user timeline, formats JSON, shows response status and headers underneath
#
#
GET http://api.twitter.com/1/statuses/user_timeline.json?screen_name=twitterapi&count=2
#
# XML is supported - highlight, pretty-print
#
GET http://www.redmine.org/issues.xml?limit=10

#
# It can even show an image!
#
GET http://upload.wikimedia.org/wikipedia/commons/6/63/Wikipedia-logo.png
#
# A bit of json GET, you can pass headers too
#
GET http://jira.atlassian.com/rest/api/latest/issue/JRA-9
User-Agent: Emacs24
Accept-Encoding: application/xml

#
# Post works too, entity just goes after an empty line. Same is for PUT.
#
POST https://jira.atlassian.com/rest/api/2/search
Content-Type: application/json

{
        "jql": "project = HSP",
        "startAt": 0,
        "maxResults": 15,
        "fields": [
                "summary",
                "status",
                "assignee"
        ]
}
#
# And delete, will return not-found error...
#
DELETE https://jira.atlassian.com/rest/api/2/version/20

Lines starting with # are considered comments AND also act as separators.

HTTPS and image display requires additional dll's on windows (libtls, libpng, libjpeg etc), which are not in the emacs distribution.

More examples can be found in the examples directory.

In-buffer variables

You declare a variable like this:

:myvar = the value

or like this:

:myvar := (some (artbitrary 'elisp)

In second form, the value of variable is evaluated as Emacs Lisp form immediately. Evaluation of variables is done from top to bottom. Only one one-line form for each variable is allowed, so use (progn ...) and some virtual line wrap mode if you need more. There's no way to reference earlier declared restclient variables, but you can always use setq to save state.

After the var is declared, you can use it in the URL, the header values and the body.

# Some generic vars

:my-auth = 319854857345898457457

# Update a user's name

:user-id = 7
:the-name := (format "%s %s %d" 'Neo (md5 "The Chosen") (+ 100 1))

PUT http://localhost:4000/users/:user-id/
Authorization: :my-auth

{ "name": ":the-name" }

Warning: If you include var declarations as part of the request, in the body or headers, it will be sent along.

Instead, place them above your calls or in separate sections. Like in the example above.

And be careful of what you put in that elisp. No security checks are done, so it can format your hardrive. If there's a parsing or evaluation error, it will tell you in the minibuffer.

Known issues

License

Public domain, do whatever you want.

Author

Pavel Kurnosov mailto:pashky@gmail.com