Restclient
Table of Contents
- links
- Tools
1. Usage
GET https://api.github.com User-Agent: Emacs Restclient
GET http://www.redmine.org/issues.xml?limit=10
GET
GET http://jira.atlassian.com/rest/api/latest/issue/JRA-9 User-Agent: Emacs24 Accept-Encoding: compress, gzip
POST https://jira.atlassian.com/rest/api/2/search Content-Type: application/json
{ "jql": "project = HSP", "startAt": 0, "maxResults": 15, "fields": [ "summary", "status", "assignee" ] }
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.
2. 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.
Variables can be multiline too:
:myvar = << Authorization: :my-auth Content-Type: application/json User-Agent: SomeApp/1.0
or
:myvar := << (some-long-elisp (code spanning many lines)
`<<` is used to mark a start of multiline value, the actual value is starting on the next line then. The end of such variable value is the same comment marker `#` and last end of line doesn't count, same is for request bodies.
After the var is declared, you can use it in the URL, the header values and the body.
2.1. Some generic vars
:my-auth = 319854857345898457457 :my-headers = << Authorization: :my-auth Content-Type: application/json User-Agent: SomeApp/1.0
2.2. 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/ :my-headers
{ "name": ":the-name" }
3. File uploads
Restclient now allows to specify file path to use as a body, like this:
POST http://httpbin.org/post Content-type: text/plain
< /etc/passwd
4. Example
GET http://httpbin.org/user-agent User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x8664; rv:31.0) Gecko/20100101 Firefox/31.0
GET http://httpbin.org/headers
GET http://httpbin.org/get?some=example¶ms=for&testing=restclient
POST http://httpbin.org/post Content-Type: application/json
{ "jql": "project = HSP", "startAt": 0, "maxResults": 15, "fields": [ "summary", "status", "assignee" ] }
GET http://httpbin.org/response-headers?Content-Type=application/vnd.whatever%2Bjson;%20charset=UTF-8
GET http://httpbin.org/response-headers?Content-Type=application/something%2Bjson
PUT http://httpbin.org/put Content-Type: application/json
{ "name": "emacs", "awesomness": 9042 }
PATCH http://httpbin.org/patch Content-Type: application/xml
[ { "replace": "/awesomness", "value": 9043 } ]
DELETE http://httpbin.org/delete If-Match: "*"
GET http://httpbin.org/status/404
GET http://httpbin.org/status/200
GET http://httpbin.org/response-headers?key=val
GET http://httpbin.org/cookies Cookie: name=restclient
:example-auth := (format "Basic %s" (base64-encode-string (format "%s:%s" "user" "password"))) GET http://httpbin.org/basic-auth/user/password Authorization: :example-auth
PUT http://httpbin.org/put Content-Type: application/json
{ "text": "\u2018a" }
GET http://httpbin.org/response-headers?Content-Type=whatever/braindamage
PUT http://httpbin.org/put Content-Type: application/json
{ "text": "привет", "text2": "João Sá", "text3": "João" }
pwd=1234
= foo\bar
:foo
:auth-token = abcd1234 :number := (+ 1 2 3 4) :text := (concat "This is " ":num" "ber")
:common-headers = << Authentication: :auth-token User-Agent: MyApp/1.0 Content-type: application/json
:common-body = << { "number": :number, "text": ":text" }
POST http://httpbin.org/post?q=1 :common-headers
:common-body
POST http://httpbin.org/post?q=2 :common-headers
{ "other": "body", "common": :common-body }
PUT http://httpbin.org/put Content-type: text/plain
< /etc/passwd
{"json": "that looks like header"}
POST http://httpbin.org/post Content-Type: text/xml
<?xml version="1.0" encoding="utf-8"?> <AAA xmlns="ns" another-attr="x"> </AAA>
GET http://httpbin.org/redirect-to?url=http%3A%2F%2Fexample.com%2F
:cookie=B=db9s6bpclha4g&b=3&s=eq
POST http://httpbin.org/post Cookie: :cookie