diepm / vim-rest-console

A REST console for Vim.
658 stars 54 forks source link

Allow the definition of global host and headers #16

Closed mjakl closed 8 years ago

mjakl commented 8 years ago

This PR fixes #15 and defines a new (optional) global section in the rest file.

Like so:

http://localhost:9200
Accept: application/json

---

# Get all ES indices

---
GET /_cat/indices?v

Please note that this is my very first try with VimScript, so check whether there are newbie mistakes. Especially the jumging around in the rest buffer seems strange to me.

Shouldn't all variables within the functions be local scoped? The default seems to be global?

mjakl commented 8 years ago

Found a bug - closing for now.

diepm commented 8 years ago

It would be great if we could specify some default values (I'm tired of y&p, too). I'm thinking of a global section like what you've done. We just need a convenient way to separate the different request bodies.

mjakl commented 8 years ago

My plan was to introduce --- as a placeholder, so a block is either delimited by an URL, or ---.

The file would look like that then:

GLOBAL BLOCK
---

---
/_cat/something
Accept: anything/at_all

---
/_cat/indices

From an implementation perspective, I wanted to replace the --- with the lines of the GLOBAL BLOCK. This PR works that way, but not 100%.

The above example would the be parsed as if it'd look like that:

GLOBAL BLOCK
/_cat/something
Accept: anything/at_all

GLOBAL BLOCK
/_cat/indices
diepm commented 8 years ago

What is the issue you've encountered that doesn't make it work 100%?

mjakl commented 8 years ago

To be honest, I do not know - it seemed that the curl request got muddled and reported something about "not supported http protocol". Maybe you could have a look at the code, I'm pretty sure it's just a small oversight... .

diepm commented 8 years ago

I've tried some examples but can't reproduce the scenario you mention. Do you have an example?

mjakl commented 8 years ago

Actually I cannot reproduce it anymore. Maybe I've had something really bad in my file and was too unsure about my VimL :)

diepm commented 8 years ago

I plan to make some changes to your PR to extend the global section feature. Specifically,

So, we can have something like this

### Global section.
// Default host.
http://localhost

// Default header settings.
Content-Type: application/json
Accept: */*
--

### Default host and headers.
--
GET /resource

### Default host with local headers.
--
Content-Type: application/x-www-form-urlencoded
Cache-Control: no-cache
// 'Accept' taken from the global section.

POST /form
form-data=value&
form-submit=1

### New host and default headers.
http://localhost:9200

GET /_cat/nodes?v

What do you think?

mjakl commented 8 years ago

Great idea! Let me know if I can help out in any way!

I'm eager to see how you approach this :)

diepm commented 8 years ago

It's finally merged and released. Hope we won't encounter any quirky bugs ;) Thanks for your great idea!

mjakl commented 8 years ago

Yeah! Just upgrading :)