Way to construct and print an URL
Zash opened this issue · 6 comments
Checklist
- I've searched for similar feature requests.
Enhancement request
A way to construct and print an URL for use elsewhere, especially URL-encoding of GET parameters.
E.g. http --print-url https://example.com/ foo==bar boop=="escape me please!"
and receive https://example.com/?foo=bar&boop=escape+me+please%21
Problem it solves
I'm working on a shell script which demonstrates how to do OAuth 2, and I need a way to open the authorization endpoint with the correct GET parameters in a browser, and would thus like to have URL encoding of the various parameters. Manually escaping e.g. &scope=this+that
is no fun to do in bash :)
The script in question uses HTTPie for everything else so reusing the syntax would be convenient.
@Zash Could you assign this issue to me? I am a beginner and this issue seems like a good first contribution.
Could you assign this issue to me?
@avnogy I have no such privileges here, but if you Just Do It and open a PR referencing this issue, the worst that could happen is that you gain some experience and it gets declared out of scope for the project 😃
@Zash If you're still working on your tutorial, you could achieve this easily just using --offline
and string manipulation in your shell. Here are two examples to get the the URL encoded path using HTTPie:
PowerShell
(http https://example.com/ foo==bar boop=="escape me please!" --offline | Select-String -Pattern '^GET\s(.+)\sHTTP/\d\.\d$').Matches[0].Groups[1].Value
Bash
http --offline https://example.com/ foo==bar boop=="escape me please" | grep --extended-regexp 'GET\s.+\sHTTP' | sed 's/GET //' | sed -E 's/ HTTP.+//'
Then just concatenate it back with the domain however you'd like. I know it's not as pretty as just --print-url, but to me it seems like that may be out of scope (I'm not a maintainer, but that's just my gut feeling). I wonder if it could maybe be written as a plugin.
Thanks, wasn't aware of --offline
. Still, it'd be awfully convenient to be able to build and print the full URL.
This is not a tutorial, I'm not sure it is even readable. Instead I sorta gave up and made a plugin for httpie.
LOL sorry, dunno where I read tutorial initially. Just re-read the post.
Plugin looks neat!