HttpRepl icon indicating copy to clipboard operation
HttpRepl copied to clipboard

[Feature] Scripting capabilities

Open joacar opened this issue 5 years ago • 8 comments

Hi,

First, thanks for this tool, it's useful for testing APIs. What I would like is a feature to execute what I here call a use-case. Lets take OAuth2 as example where one first sends a request for token, the token is retrieved and then subsequent calls set the header Authorization "Bearer <token>". Today I have this text file that serve as template and I execute it using run <file>,

get_token.txt

cd /connect/token
post -h content-type=application/x-www-form-urlencoded -c grant_type=client_credentials&client_id=<id>&client_secret=<secret>&scopes=<scopes>
set header Authorization "Bearer <token>"

Once I get the token I copy the last line from above and then paste the retrieved token.

It would be nice to have the ability to specify above as a CSharp file (or other, just don't another scripting language :)) and get it interpreted so we can have scripting capabilities. get_token.cs

cd /connect/token // For OAuth introspection .well-known/openid-configurations could be utilized
Json response = post -h ..  // parse based on accept header
set header Authorization $"Bearer {response.Token}"

joacar avatar Oct 14 '20 12:10 joacar

Thanks for the suggestion! Expanding on the scripting capabilities is definitely something we want to do in a future release and being able to pipe the output of one command into another command is definitely on our radar.

For your specific scenario, I think we will also be looking at ways to streamline the authorization process as well so you're not having to piece together the raw commands.

No definite plans on either of those things yet, but they're on our radar.

tlmii avatar Oct 15 '20 21:10 tlmii

@joacar - do you know of any existing tech that would be similar to the experience you're defining?

bradygaster avatar Oct 20 '20 21:10 bradygaster

@bradygaster No. Was some time ago I last used SmartBear UI but I think that you could record steps with some scripting capabilities. For CLI httprepl is the first I've seen. I like it so far, much more convenient then writing custom bash scripts.

joacar avatar Oct 21 '20 11:10 joacar

Would accessing environment variables be an option here? It woul`d have the benefit that things like this would work. Some pseudo-PowerShell-code:

$token = (az account get-access-token --query accessToken -o tsv)
$env:AuthHeader = "bearer $token"
httprepl https://my.site/api
set header Authorization ENV['env:AuthHeader']

That way scripting would be easier for @joacar `s case and any other scripting platform too.

devdeer-alex avatar Dec 07 '20 20:12 devdeer-alex

Slightly better but still it can't be integrated in the httprepl flow completely. But opening up for --query (or similar) in httprepl in combination can be useful.

cd /connect/token
$token = (post -h content-type=application/x-www-form-urlencoded -c grant_type=...&client_secret=... --query access_token) <-- Syntax like this
set header Authorization "Bearer $token"

joacar avatar Dec 08 '20 13:12 joacar

Just found this that could be worth looking into!

joacar avatar Jan 14 '21 13:01 joacar

That does look nifty. I will do some investigation on what's possible when we combine these.

bradygaster avatar Jan 22 '21 16:01 bradygaster

I am also interested in the ability to script HttpRepl commands. In particular, I would like to be able to script the commands in bash with Jupyter Notebooks in VS Code. Alternatively, add kernel support for HttpRepl in order to run the scripts.

troydalldorf avatar Jul 26 '23 12:07 troydalldorf