Vscode-restclient: [Feature] Import/require .(http|rest) file

Created on 3 Apr 2018  路  13Comments  路  Source: Huachao/vscode-restclient

  • VSCode Version: 1.21.1
  • OS Version: Ubuntu 18.04
  • REST Client Version: 0.18.1
    It would be nice to be able to import/require file. Eg.
#### login.http
# @name login
@url = https://myawesomesite.com

POST {{url}}/api/auth HTTP/1.1

{
"username":"user",
"pass": "pass"
}

Then you could import/require files like:

import './login.http'

GET {{url}}/api/list HTTP/1.1
Authorization: Bearer {{login.response.body.$.data.id}}

enhancement

Most helpful comment

Hi, this feature would be really helpful to write DRY request files.

Currently I'm repeating the auth.http content in every .http file...

All 13 comments

@mtxr nice suggestion, I will consider it carefully.

Any update on this?

I am so sorry that I'm busy in my work, and I also put the feature that file variable can reference other variable in first priority

Hi, any update on this? Really looking forward for this feature

Hi, this feature would be really helpful to write DRY request files.

Currently I'm repeating the auth.http content in every .http file...

This features would be really cool.

I'm interested in this, if you have any ideas on how you want to do it. i can help you build it out.

Any Update on this ??? , I am really looking forward to it

@dv29 want to try some implementation and get feedback?

I'm also very interested in this, and thinking about giving it a shot. But first, we need to agree on a few things.

The statement syntax

I would prefer to follow the pattern of prefixing keywords with @ inside a comment, like it is done with @name. So what do you think about the following?

# @import './login.http'

GET {{url}}/api/list HTTP/1.1
Authorization: Bearer {{login.response.body.$.data.id}}

The keyword name

I see that we have a few options: include, import, require.

My personal preference is for include, since this is basically going to be treated like a preprocessor include, as if we had copied and pasted the code into the new file. Any objections?

The tasks

  • [ ] Introduce include/import/require resolution to the send request command
  • [ ] Update http language definition to support the new include/import/require statement
  • [ ] Document usage in the readme
  • [ ] (optional) offer auto-complete for included file paths

Corner cases

  • Nested includes: can we agree that file paths will always be relative to each file that called the @include statement?

Anything else?

@rdumont : Happy to see you're planning to work on this.
Pls keep us informed.

@rdumont we're also very much interested in this feature, please let us know of the progress! :)

+1

Was this page helpful?
0 / 5 - 0 ratings