Allow setting of default base_url
See original GitHub issueHi there, first of all httpie
is an excellent library. I recently switched to it after using resty
for ages.
One of the nice features i am missing is a way to set a base url that will be used for subsequent http
invocations.
I often find myself issuing multiple rest calls when testing/browsing an API and defining a base url saves me from a lot of typing.
For example, assume the following base url:
https://api.example.com/api/v1
When issuing the following command
http GET /users
Will do a GET request to the resource located at https://api.example.com/api/v1/users
.
Currently I solve my impediment by applying the following patch to the httpie
library
diff --git a/httpie/input.py b/httpie/input.py
index 8eb6a7d..e49079d 100644
--- a/httpie/input.py
+++ b/httpie/input.py
@@ -131,6 +131,8 @@ class Parser(ArgumentParser):
self._parse_items()
if not self.args.ignore_stdin and not env.stdin_isatty:
self._body_from_file(self.env.stdin)
+ if 'HTTPIE_BASEURL' in os.environ:
+ self.args.url = os.environ['HTTPIE_BASEURL'].rstrip('/') + self.args.url
if not (self.args.url.startswith((HTTP, HTTPS))):
scheme = HTTP
This allows me to define a base url for the current running shell:
export HTTPIE_BASEURL='https://api.example.com/api/v1'
http GET /users
http GET /users/8292
I am curious what you think about this approach and maybe have a better idea. I would be happy to contribute to this idea if needed.
Keep up the great work.
Issue Analytics
- State:
- Created 9 years ago
- Reactions:3
- Comments:11 (3 by maintainers)
Top GitHub Comments
@jakubroztocil I would vote for this feature, using http-prompt is not always convenient
Have a look at https://github.com/eliangcs/http-prompt if you’re interested in this feature.