VSCodeのrestclient 互換の http client
.gitignore | 4 years ago | ||
README.md | 4 years ago | ||
restclient-vscode-compatible.el | 4 years ago |
This program is forked from restclient.el(https://github.com/pashky/restclient.el/blob/master/restclient.el).
This is a tool to manually explore and test HTTP REST webserver. Runs queries from a plain-text quert sheet, displays results as a pretty-printed XML, JSON and even images. It's also compatible with vscode-restclient(https://github.com/Huachao/vscode-restclient)
This code customize restclient(https://github.com/pashky/restclient.el/blob/master/restclient.el) to use original variable '@my_value' compatiabled with vscode-restclient.
// Feature work: // Should install from MELPA.
You can easily install restclient
from github.
How to download:
git clone https://www.yatex.org/gitbucket/git/Asya-kawai/restclient-vscode-compatible.git cp restclient-vscode-compatile/restclient-compatible-vscode.el /path/to/elisp/.
Alternatively, deploy restclient-vscode-compatible.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:
C-c C-c
: runs the query under the cursor, tries to pretty-print the response (if possible)C-c C-r
: same, but doesn't do anything with the response, just shows the bufferC-c C-v
: same as C-c C-c
, but doesn't switch focus to other windowC-c C-p
: jump to the previous queryC-c C-n
: jump to the next queryC-c C-.
: mark the query under the cursorC-c C-u
: copy query under the cursor as a curl commandC-c n n
: narrow to region of current request (including headers)TAB
: hide/show current request body, only ifC-c C-a
: show all collapsed regionsThe last two functions are implemented as restclient-outline-mode
minor mode, which is activated by default via hook for major mode. Remove this hook using (remove-hook 'restclient-mode-hook 'restclient-outline-mode)
if you don't wish to have this behaviour, or it clashes with any other binding for TAB
like autocomplete.
Query file example:
# -*- restclient -*- # # Gets all Github APIs, formats JSON, shows response status and headers underneath. # Also sends a User-Agent header, because the Github API requires this. # GET https://api.github.com User-Agent: Emacs Restclient # # 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: compress, gzip # # 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.
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.
# Some generic vars @my-auth = 319854857345898457457 @my-headers = << Authorization: :my-auth Content-Type: application/json User-Agent: SomeApp/1.0 #
# 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" }
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
There are several variables available to customize restclient
to your liking. Also, all font lock faces are now customizable in resclient-faces
group too.
Default: t
Determines whether restclient logs to the *Messages* buffer.
If non-nil, restclient requests will be logged. If nil, they will not be.
Default: t
Re-use same buffer for responses or create a new one each time.
If non-nil, re-use the buffer named by rest-client-buffer-response-name
for all requests.
If nil, generate a buffer name based on the request type and url, and increment it for subsequent requests.
For example, GET http://example.org
would produce the following buffer names on 3 subsequent calls:
*HTTP GET http://example.org*
*HTTP GET http://example.org*<2>
*HTTP GET http://example.org*<3>
Default: *HTTP Response*
Name for response buffer to be used when restclient-same-buffer-response
is true.
Default: nil
Inhibit restclient from sending cookies implicitly.
#
act as end of entity. Yes, that means you can't post shell script or anything with hashes as PUT/POST entity. I'm fine with this right now, but may use more unique separator in future.localhost
might fail because of that bug in Emacs/url.el. As a workaround you can use 127.0.0.1
instead of localhost
.Public domain, do whatever you want.
Toshiki Kawai kawai-tohsiki@aintek.xyz