diepm / vim-rest-console Goto Github PK
View Code? Open in Web Editor NEWA REST console for Vim.
A REST console for Vim.
Using fresh install of plugin using Vim 8.0, I get the below error on trigger with a single-line block:
http://localhost:8080 POST /data {"ids": ["25f7c2e5"] }
line 34:
E121: Undefined variable: curlOpts
E116: Invalid arguments for function vrc#opt#DictHasKeys(curlOpts, ['-i', '--include']) })
E116: Invalid arguments for function <SNR>67_DisplayOutput
Line-separating the host, method, and payload resolves the error.
If the above single-line syntax is not supported, should the README examples be updated to reflect this?
I really like this plugin. Sometimes I use this instead of postman.
But, sometimes I turn back to postman because I could easily access saved request. Therefore, I don't have to recreate my request detail.
Is it possible to make a list of saved request and automatically open those list when I open rest console? Therefore I could click my saved request and replay it.
It will be nice if I just paste my curl command, block it, and run something like :VRCParseCurl
and magically get correct vrc request.
What do you think?
Thanks! :)
Hi,
amazing tool that I use daily at work and thus starting to wanted new features :-)
So it's not really an issue, but is it possible to to define variables? For examples to be able to do something like this:
http://localhost:1234
--
var city = blablabla
var street = lolalo
--
GET /city/$city/street/$street
--
GET /city/$city/street/$street/number/3
So when I want to make my call on another city/street, I don't need to change it in every endpoints.
Thanks, Cheers
Hello,
I really like this because I don't have to leave vim to test an endpoint but recently it's stopped working.
I can curl the given url http://localhost:3000/v2/showers
and it works fine, I can also use visual studio code's rest client and that works. But whenever I use the vim rest console I just get a blank curl output.
This is what my file looks like:
http://localhost:3000
GET /v2/showers
Accept: application/json
User-Token: <token>
and this is the output I'm getting in the response buffer
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
Also, I can at least see it hitting the server, I think. Whenever I press ctrl+j
I get a blank line in my rails log which I believe means it's at least getting to the server but the route is not actually getting hit. Any ideas?
I added the plugin, set the file type and put the command and the url. But after triggering the request, nothing is happening...
Can it be that it is not working in neovim?
When I set just the let g:vrc_show_command = 1
configuration option without changing the vrc_auto_format_response_*
defaults, JSON responses that I receive are unformatted. The response headers include Content-Type
. Without setting the vrc_show_command
option, the response is formatted as expected.
I did not find anything in the README regarding this but I apologize if I overlooked something. I just updated the plugin before posting this.
how can I set a POST request its content-type?
i found it removed in commit:
commit ac3f383b0953041145634a58c00ad090b93220dc
Author: diepm <[email protected]>
Date: Fri May 26 00:43:35 2017 -0500
Support raw cUrl options
but why? this option is very important for debugging rest apis.
I found this is still buggy.
so say I put this in .vimrc:
let g:vrc_show_command = 1
let g:vrc_curl_opts = {
\ '-sS': '',
\ '--connect-timeout': 10,
\ '-i': '',
\ '--max-time': 60,
\ '-k': '',
\}
then in my file I have:
http://localhost:8095
-u admin:abc
#GET /virtual-network/5e5f3cf7-b1aa-4b91-976e-23350916ccf7
GET /
the curl got executed is this:
|| curl -sS -k --get 'http://localhost:8095/'
so it still miss the -u "admin:abc".
as long as I comment out the "let g:vrc_curl_opts" setting in .vimrc, it works.
so it looks let g:vrc_curl_opts does not work for me.
I've found that the -u
option ends up being passed twice, once with an unescaped space after the colon, causing errors
This request:
https://reqres.in/api
-u user:pass
POST /users
{
"foo": "bar",
"baz": "quux"
}
Gives me this command:
|| curl -s -u 'user:pass' -H 'Content-Type: application/json' -H -u user: pass -w '%{http_code}' -S -X POST --data '{ "foo": "bar", "baz": "quux"}' 'https://reqres.in/api/users'
in my setup I need to give curl a username and password to access those APIs.
how to use this plugin in this context?
StrongLoop LoopBack REST APIs can use serialized JSON objects in their query string.
/api/example?filter={"where":{"id":1234}}
Brackets in cURL are for globbing, so a solution is to include the -g
option to disable globbing.
Is there (or can we have) an option to append arguments to the cURL command, either globally or as-needed?
Other solutions are welcome as well.
see https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Request_methods
Thanks for your plugin
When I look at your sample.rest you repeat http://localhost:9200 many times. I'm lazy. What I would like to be able to do is to write the host just one time and then have multiple rest requests with the same host and headers:
# Submitting a form.
http://localhost:9200
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
GET /_cat/nodes?v
POST /testindex/testtype
{
"name": "some name",
"value": "some value",
"date": "2015-01-01"
}
GET /testindex/_search?pretty
#end of the block
When I trigger on the POST or its body it'll execute the POST request with the host and header defined above.
What do you think?
Right now there is no option to disable mapping, any plans to change it?
this would be useful to get an auth token
I'm thinking about something:
export TOKEN=Cookie=`curl https://swapi.co/api/people/1/ |jq --arg --raw-output '.name'`
echo $TOKEN
a way to pipe the curl output would be also usefull - when the return value is long it's hard to check it in vim - piping to jq or tail could be interesting
filetype
can also be set in the output buffer on an ad hoc basis.# vim: set ft=json
But I can't change anything in the output buffer because modifiable is off.
let g:vrc_output_buffer_name = '__VRC_OUTPUT.<filetype>'
This creates a buffer with that name literally, does not add the filetype.
I suspect this is because my server doesn't set the content type.
But I know I will be getting JSON. I'd like to be able set the file type for the response as an option in my .rest file on a per request basis.
And, ideally, I'd like to be able to pipe the response through jq
or json_pp
before it appears, is that possible?
I'm trying to have a PUT request use the --data-binary curl option, but it seems the plugin seems to be adding --data and putting the flag as the data. See example below
# Global scope.
let g:vrc_curl_opts = {
\ '--data-binary': '~/Desktop/img.jpg'
\}
--
--
PUT /url/img
--data-binary: '@~/Desktop/img.jpg'
curl -X PUT --data '--data-binary @~/Desktop/img.jpg' '/url/img'
How would I tell the plugin to use data-binary instead of data?
This is a fantastic tool, and this is not really an issue but, when I use windows I have to escape the request JSON like this:
http://localhost/
POST /testService
{
"id" : 6
}
It would be nice not escaping quotes needed
I will continue using it like this, thank you so much for this amazing tool
Best Regards
Thanks for creating this awesome plugin ๐
I would send you a pull request for this but I am not good at viml
Since this plugin uses curl, it would be great if there was a way to pass options directly to curl, for instance I was trying to find a way to make a multipart POST and didn't find a way to do that using VRC. curl however supports this. If we could add a way to pickup the text after a curl-raw in the request line or before request line, something like below
http://api.localhost:4444
curl-raw --form 'file=@/tmp/upload'
GET /
Thanks again for creating this plugin :)
Hi,
Im trying to test with gitlab API:
https://gitlab.com
GET /api/v4/projects
But I only get:
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
@
With a single curl this works:
curl "https://gitlab.com/api/v4/projects"
But if I try with github this works:
https://api.github.com
GET /users/oemunoz
Im forgeting something to work with gitlab ?
hey, nice plugin.
but there is no way to change, which split should be open. horizontal/vertical split. any change to get that feature? :)
I get unformatted server response. After a brief debugging I discovered that in line 640 there is:
let formattedBody = system(
\ formatCmd,
\ getline(emptyLineNum, '$')
\)
The problem is that getline
function returns an array containing headers and response. I've tried setting it to getline(emptyLineNum, '$')[-1]
and this makes output formatted but then headers section is invisible.
I have network issues with some of the systems I work with and would love to get curl to timeout fast.
As it is, the plugin tries for many seconds (60?) and then displays a timeout error in the output buffer. If I touch any key during the timeout vim (via tmux) is left in a bad state until I restart.
Anyway to pass args to cURL? Some obvious trick I'm missing? If not, would a pull request to tunnel args to cURL be welcome?
Btw, this plugin is GREAT! I've used it every day for months. Thx.
Anytime I try to run a DELETE request it jumps the cursor down under my status bar and things get all wonky and I have to ctrl-c to even be able to :q
. Here's an example request
http://localhost:3000
DELETE /users/jon
All my other requests always work great and cause no problems, but DELETE is causing an issue every time I try it. It still works and executed the request, but I have to quite and jump back in to continue on.
I'm on OSX 10.11.5
Vim 7.4.1054
It would be nice if it was possible to set header values in the buffer :)
It would be very useful when sending requests that must be authenticated with the Authorization
header.
It would be great if, when the Content-Type, is say, pdf, to delegate the opening to a pdf viewer.
I've been running curl
from the vim command line for a while now and have not been able to figure out how to get curl
to two important things at the same time:
It looks like this plugin suffers the same humiliation:
IMO the progress meter is annoying and irrelevant 99.9% of the time.
Maybe a different http client would work better?
I know I could attach a json to do bulk ES query. But, is it possible to do it inline?
I've tried this but keep getting error
http://localhost:9200
post /_bulk
{ "delete": { "_index": "website", "_type": "blog", "_id": "123" }}
{ "create": { "_index": "website", "_type": "blog", "_id": "123" }}
{ "title": "my first blog post" }
{ "index": { "_index": "website", "_type": "blog" }}
{ "title": "my second blog post" }
{ "update": { "_index": "website", "_type": "blog", "_id": "123", "_retry_on_conflict" : 3} }
{ "doc" : {"title" : "my updated blog post"} }
HTTP/1.1 400 Bad Request
content-type: application/json; charset=UTF-8
content-length: 235
{
"error": {
"reason": "Validation Failed: 1: no requests added;",
"root_cause": [
{
"reason": "Validation Failed: 1: no requests added;",
"type": "action_request_validation_exception"
}
],
"type": "action_request_validation_exception"
},
"status": 400
}
We are working with several (test) environments and it would be fantastic to easily switch between them by changing a single setting instead of search/replace through the whole file.
Since the http
or https
start the request block, maybe a viable option would be to allow variables to be used in the URL?
For example:
#ENVIRONMENT=api
ENVIRONMENT=test-api
https://$ENVIRONMENT.example.com
GET /debug/ping
By setting the right ENVITONMENT
variable it'd be quick and easy to switch around between different setups and it would not interfere with existing VRC scripts.
Hi,
Can I authenticate in some rest API using OAuth2?
Thanks
Since the last update, it looks like the plugin automatically includes the -k
flag if the URL has https.
On Mac, it produces:
curl: (35) SSL peer handshake failed, the server most likely requires a client certificate to connect
Running the cURL command without the -k
option returns the expected results.
Is there a way to disable the automatic inclusion of that option?
It would be great if you could set default querystring parameters in the global section, for example to add pretty
to a querystring in each request (useful for elasticsearch.)
create sample.test file
`// Examples of some ElasticSearch requests.
http://172.28.128.3:9200
GET /_search
result:
HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Content-Length: 684
{
"_shards": {
"failed": 0,
"successful": 5,
"total": 5
},
"hits": {
"hits": [
{
"_id": "2",
"_index": "index",
"_score": 1.0,
"_source": {
"content": "\u516c\u5b89\u90e8\uff1a\u5404\u5730\u6821\u8f66\u5c06\u4eab\u6700\u9ad8\u8def\u6743"
},
"_type": "fulltext"
},
{
"_id": "4",
"_index": "index",
"_score": 1.0,
"_source": {
"content": "\u4e2d\u56fd\u9a7b\u6d1b\u6749\u77f6\u9886\u4e8b\u9986\u906d\u4e9a\u88d4\u7537\u5b50\u67aa\u51fb \u5acc\u72af\u5df2\u81ea\u9996"
},
"_type": "fulltext"
},
{
"_id": "1",
"_index": "index",
"_score": 1.0,
"_source": {
"content": "\u7f8e\u56fd\u7559\u7ed9\u4f0a\u62c9\u514b\u7684\u662f\u4e2a\u70c2\u644a\u5b50\u5417"
},
"_type": "fulltext"
},
{
"_id": "3",
"_index": "index",
"_score": 1.0,
"_source": {
"content": "\u4e2d\u97e9\u6e14\u8b66\u51b2\u7a81\u8c03\u67e5\uff1a\u97e9\u8b66\u5e73\u5747\u6bcf\u5929\u62631\u8258\u4e2d\u56fd\u6e14\u8239"
},
"_type": "fulltext"
}
],
"max_score": 1.0,
"total": 4
},
"timed_out": false,
"took": 2
}
`
content auto convert unicode
how to convert utf8?
If I want to share my requests with people who aren't using vim
or vim-rest-console
it would be nice to be able to emit the curl command(s) that would be executed rather than actually executing them.
Hi there,
Would it be possible to work on the following things to get a minimal interoperability with postman :
Thanks !
http://localhost:9200/
GET _search?
{
"query": {
"query_string": {
"default_field": username,
"query": "k* OR m* OR h*"
}
}
}
This returns this error:
HTTP/1.1 400 Bad Request
content-type: application/json; charset=UTF-8
content-length: 477
{
"error": {
"reason": "request [/_search] contains unrecognized parameter: [{ \"query\": { \"query_string\": { \"default_field\": username, \"query\": \"k* OR m* OR h*\" } }}]",
"root_cause": [
{
"reason": "request [/_search] contains unrecognized parameter: [{ \"query\": { \"query_string\": { \"default_field\": username, \"query\": \"k* OR m* OR h*\" } }}]",
"type": "illegal_argument_exception"
}
],
"type": "illegal_argument_exception"
},
"status": 400
}
But the query passes when done through Sense.
The plugin intentionally omits the -X
curl flag when the verb is POST, which is causing me issues with a certain POST api that doesn't require data in the body, in which case the curl command from VRC will effectively be a GET.
Easy to patch, but I was first wondering why this was done?
https://github.com/diepm/vim-rest-console/blob/master/ftplugin/rest.vim#L294
the output is only 1 line always.
is there a way to automatically display the formatted output , e.g. using python -mjson.tool ?
This is of course no bug, but a suggestion for a Tips'n'Tricks section of the documentation.
If the appropriate ftplugin is installed, it is very easy to enable output syntax highlighting (especially for JSON) with this in your .vimrc
:
let b:vrc_output_buffer_name = '__VRC_OUTPUT.json'
Alternatively, it might be possible to set it per request buffer using a special modeline (requireing let-modeline):
# vim: let b:vrc_output_buffer_name = '__VRC_OUTPUT.json'
Thanks, VRC is a great idea!
When the headers are included in the output -i
the vrc_auto_format_response_patterns
seems to be ignored.
The syntax highlighting is working correctly.
If I set vrc_response_default_content_type
and I don't use the -i
flag the response pattern is followed.
let g:vrc_auto_format_response_patterns = {
\ 'json': 'jq "."',
\ 'xml': 'xmllint --pretty 2 -',
\}
let g:vrc_response_default_content_type = 'application/xml'
http://localhost:8002
--digest
-sSi
Accept: application/xml
GET /manage/v2/databases/umls-content
HTTP/1.1 401 Unauthorized
Server: MarkLogic
WWW-Authenticate: Digest realm="public", qop="auth", nonce="36095a2cff4d4c:Uyrdh4EMtOF9A415HEfnuA==", opaque="ba88a12c6bb8e5a1"
Content-Type: application/xml; charset=utf-8
Content-Length: 178
Connection: Keep-Alive
Keep-Alive: timeout=5
HTTP/1.1 200 OK
Content-type: application/xml; charset=UTF-8
Cache-Control: no-cache
Expires: -1
Server: MarkLogic
Content-Length: 3827
Connection: Keep-Alive
Keep-Alive: timeout=5
<database-default xsi:schemaLocation="http://marklogic.com/manage/databases manage-databases.xsd" xmlns="http://marklogic.com/manage/databases" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<id>2512891749582821713</id>
<name>umls-content</name>
<meta>
<uri>/manage/v2/databases/umls-content</uri>
<current-time>2018-03-13T22:06:04.904602-04:00</current-time>
<elapsed-time units="sec">0.142412</elapsed-time>
</meta>
</database-default>
The xml is not being piped through xmllint --pretty 2 -
. However, when I drop the -i
the results are piped through as expected
http://localhost:8002
--digest
-sS
Accept: application/xml
GET /manage/v2/databases/umls-content
<?xml version="1.0"?>
<database-default
xmlns="http://marklogic.com/manage/databases"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://marklogic.com/manage/databases manage-databases.xsd"
>
<id
>2512891749582821713</id
>
<name
>umls-content</name
>
<meta
>
<uri
>/manage/v2/databases/umls-content</uri
>
<current-time
>2018-03-13T22:12:50.330991-04:00</current-time
>
<elapsed-time
units="sec"
>0.171058</elapsed-time
>
</meta
>
</database-default
>
If I try this example from Elasticsearch Definitive Guide:
http://localhost:9200
GET /megacorp/employee/_search
{
"query" : {
"match" : {
"last_name" : "smith"
}
}
}
Based on the results, it seems the query body is not passed along - all the documents are returned. When I try the same example in the Sense Chrome plugin, it works as expected.
Since the plugin uses cUrl, which supports GET request with body data, could this feature be added?
I have rest api in rails and params should be nested like user[name]=some name
how to do it in rest buffer?
example I use:
http://localhost
POST /users
user[name]=some name
When I send it from vim rest console rails don't know how to parse request ActionDispatch::ParamsParser::ParseError (795: unexpected token at 'user[name]=some name'):
but when I send request from curl it seem to be working.
What am I doing wrong?
If body defined with GET methon, it is not send. But elasticsearch uses it.
curl can post data to GET.
https://www.elastic.co/guide/en/elasticsearch/reference/1.6/search-request-body.html
Can you implement this?
Thanks
Hope I didn't miss something in the docs..
It would be neat if within a request block of multiple requests, visual select only one request and run it.
Thanks for this plugin! Loving it so far!
It would be nice if I could pull in, say for example, an API key from an environment variable, and set it in the global section:
http://dev.virtualearth.net/REST/v1
-s
-i
key=$BING_MAPS_KEY
--
--
GET /Locations/40.54377,-105.02996?key=:key
--
GET /Elevation/List?points=40.54377,-105.02996&key=:key
It seems that this would need to be a new feature added to ParseVals
?:
vim-rest-console/ftplugin/rest.vim
Line 241 in 9371b81
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.