Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JavaScript code evaluation #521

Open
Maximus1285 opened this issue Feb 12, 2020 · 16 comments · May be fixed by #674
Open

JavaScript code evaluation #521

Maximus1285 opened this issue Feb 12, 2020 · 16 comments · May be fixed by #674

Comments

@Maximus1285
Copy link

It'd be nice to have the option of including JS code snippets to be resolved when sending the request

@davobutt
Copy link

Yeah this would be really good. Postman's ability to run scripts pre-request is handy for doing simple things like setting dates in the future. I guess there is a slightly elaborate workaround for this in REST client. You could run a local server which executes your script and responds in json which the REST client file can extract the variables from?

@jnorkus
Copy link

jnorkus commented Feb 28, 2020

I am about to migrate from Postman. This is the only feature missing. I don't think running a local server would convince my team.

@xslim
Copy link

xslim commented Mar 31, 2020

I need to apply encription / decryption for all requests, so pre&post JS processing would be awesome!

@RimiX2
Copy link

RimiX2 commented Apr 3, 2020

It would be POSTMAN-killer feature!

@robermorales
Copy link

Yeah I would also like to have some scripting abilities.

@robermorales
Copy link

At least, some more complex variable processing to cover most of cases: like replacing only a substring of a variable, things like that. Some "templating" abilities can be enough.

@NickClark
Copy link

It would be handy, for JSON, to have a jq style post filter ability.

@maslow
Copy link

maslow commented Jul 19, 2020

I am looking for this feature then arrived here. It would be handy.

Add custom-filter or hooks during req & res duration.

@afeblot
Copy link

afeblot commented Aug 28, 2020

It would be handy, for JSON, to have a jq style post filter ability.

Yes, it would!! Ideally, integrated in the rest client output pane. Or a way to integrate or "pipe" to existing vscode jq extensions such as jq-vscode or VSCode jq playground.

Maybe we're not that far from such an integration: VSCode jq playground is already able to apply jq filters to any opened file or unsaved buffer, specified by its path or name. But it seems the rest client output pane is a different object which VSCode jq playground does not recognize: it looks like we'd just need an option in the rest client to send the json part of the rest call response to a given file.

AnWeber added a commit to AnWeber/vscode-restclient that referenced this issue Aug 30, 2020
@AnWeber AnWeber linked a pull request Aug 30, 2020 that will close this issue
@showenx
Copy link

showenx commented Nov 13, 2020

First of all, love this extension, I was searching some solution for code blocks in the extension, I just want to throw some ideas, maybe helpful or not.

Is it possible for variable resolution, using IIFE style ( similar to other ****Monkey chrome extensions) to wrap up user's custom code block?

e.g.

(function (param) {
    'use strict';

    /*
     * user custom code block goes here
     */

    return param + '->output';
})('input');

The similar feature in postman pre-request script

@asos-gurpreetsingh
Copy link

on the home page for this extension it says "Generate code snippets for HTTP request in languages like Python, JavaScript and more" but have not seen any examples or documentation around this feature

@davobutt
Copy link

on the home page for this extension it says "Generate code snippets for HTTP request in languages like Python, JavaScript and more" but have not seen any examples or documentation around this feature

That is a feature that turns your request in to code that sends the same request.. If you do the "Rest Client: Generate code snippet" action you'll see what it does.

@kibiz0r
Copy link
Contributor

kibiz0r commented Nov 18, 2021

I had an idea on this... What if we treated code blocks similarly to request blocks?

You give them a name, they are executed linearly top-to-bottom, with the stdout cached -- and if it can be parsed as JSON then you can treat it as JSON when referencing it later on.

We could even have some double-meaning with the language annotation:

  1. It gives us nice Markdown syntax highlighting
  2. It tells us what interpreter to use, effectively a #! shebang (defaulting to bash)

Example foo.http:


# @name randomData
```ruby
mac = 6.times.map { ("%02x" % rand(256)).upcase }.join(":")
name = ["dingus", "dorkus", "derp"].sample
puts({ mac: mac, name: name }.to_json)
```

###

POST localhost:3000/devices
content-type: application/json

{
  "name": {{randomData.name}},
  "macAddress": {{randomData.mac}}
}

@piyushchauhan2011
Copy link

Any updates on this ? like running pre and post js code

@asampal
Copy link

asampal commented Mar 14, 2024

@piyushchauhan2011, you can take a look at httpyac. I switched to that quite a while ago. It's more actively maintained and has more features. https://github.com/AnWeber/httpyac

@piyushchauhan2011
Copy link

Thanks for the links @asampal . Hope restclient also add similar features, but httpyac seems to have good progress at present moment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.