vscode-restclient icon indicating copy to clipboard operation
vscode-restclient copied to clipboard

could you please add some before/after script ?

Open kingwrcy opened this issue 6 years ago • 22 comments

My server API is need RSA sign verify,How can I sign my request body before send request to server?

If I could execute script before send request to server,I can sign it.

kingwrcy avatar May 14 '18 09:05 kingwrcy

@kingwrcy This is in my plan. Thanks for your suggestion.

Huachao avatar May 14 '18 09:05 Huachao

Thanks,it also prevent me to use fully without this function.

euleryang avatar Sep 13 '19 14:09 euleryang

@kingwrcy This is in my plan. Thanks for your suggestion.

I think it will be a great Release.Would you tell me when it release. Thank you for your reply!

euleryang avatar Sep 13 '19 15:09 euleryang

as a workaround, i converted my REST request to python (using the tooling provided), and simply pre-pended the necessary script, which for me was to deflate my body, in python

worked a treat, i'm sure there will be a better solution in the future... 🙂

m1nkeh avatar Sep 25 '19 06:09 m1nkeh

This is currently the only thing preventing my migration from Postman.

jnorkus avatar Feb 28 '20 15:02 jnorkus

I need this feature badly, too. Is it in the plan?

Piean avatar Mar 06 '20 08:03 Piean

@Piean still under investigation

Huachao avatar Mar 06 '20 08:03 Huachao

This PR solves it for me. Would it work in your case @Piean ? https://github.com/Huachao/vscode-restclient/pull/532

jnorkus avatar Mar 06 '20 08:03 jnorkus

@jnorkus I think it's still a bit different, PR #532 provides the ability that executes the Shell command, this issue mainly focuses on the ability that we can do some kind of custom works before request and/or after response. And this feature can even expose some JavaScript APIs for extension users to do what they want as other REST tools like Postman.

And I am considering your PR to add it into my extension. Good Job @jnorkus

Huachao avatar Mar 06 '20 09:03 Huachao

I understand that @Huachao but the OP and possibly @Piean might solve their issue with my solution. In my case I needed to generate an auth token and I thought a before script was the way to go. But $eval actually works fine and is much more simple.

jnorkus avatar Mar 06 '20 09:03 jnorkus

I understand that @Huachao but the OP and possibly @Piean might solve their issue with my solution. In my case I needed to generate an auth token and I thought a before script was the way to go. But $eval actually works fine and is much more simple.

One of the parameters of my request is that it needs to be calculated by MD5 with other parameters.

Piean avatar Mar 06 '20 09:03 Piean

@Piean I don't have details on your use case and what exactly you need to do but this is what I currently use on my fork:

"Authorization": "Bearer {{$eval node generate_token.js %token}}"

generate_token.js is a custom node script that accepts an input (%token - read from vscode settings) and returns a generated auth token. Could something similar work for you?

jnorkus avatar Mar 06 '20 09:03 jnorkus

@jnorkus Your solution is very close to what I am looking for, thank you very much!

What do you think about resolving file variables instead of vscode settings variables? This would provide more flexability. This might be useful in scenarios where you need to pass the result of an previous eval. You would still be able to assign a vscode setting to a file variable which in turn gets referenced in the eval.

For example I am not able to implement the bitfinex headers without passing file variables to the eval: https://docs.bitfinex.com/docs/rest-auth

autrk avatar Mar 06 '20 21:03 autrk

@jnorkus My case is different from yours, for example:

POST host/url HTTP/1.1
Content-Type: application/json

{
  "param1": "value1",
  "param2": "value2",
  "sign": $MD5("param1" + value1 + "param2" + value2)
}

The "sign" is all of other parameters join by parameter name and value one by one, then MD5. Your %token is a file variable, It is constant. But my inout for the expression is changed with request parameters

Piean avatar Mar 07 '20 01:03 Piean

@Huachao When will this feature be released. I wish I could have used this feature earlier.

liucaihe avatar Apr 06 '20 15:04 liucaihe

as a workaround, i converted my REST request to python (using the tooling provided), and simply pre-pended the necessary script, which for me was to deflate my body, in python

worked a treat, i'm sure there will be a better solution in the future... 🙂

@m1nkeh i was wondering on the home page it says "Generate code snippets for HTTP request in languages like Python, JavaScript and more" but i could not find any examples of that, is it something similar you were talking about ? could you please provide an example of what you did ? Thanks

asos-gurpreetsingh avatar Apr 22 '21 10:04 asos-gurpreetsingh

Was this feature implemented?

darewreck54 avatar Jun 26 '21 12:06 darewreck54

look forward to this feature!

chengjianhua avatar Jan 05 '24 14:01 chengjianhua

look forward to this feature too!

chaoedu avatar Jan 09 '24 12:01 chaoedu

look forward to this feature!

lovelinxue avatar Feb 03 '24 03:02 lovelinxue

@Huachao
作者你好,想问一下。这个插件还会维护么? 这个功能后续还会加进去么?

感谢!

lovelinxue avatar Feb 28 '24 07:02 lovelinxue

It's still in the plan? look forward to this feature for a long long time, more than 4 years .

Alexander-Chiang avatar Apr 16 '24 08:04 Alexander-Chiang