question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow setting of default base_url

See original GitHub issue

Hi 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:closed
  • Created 9 years ago
  • Reactions:3
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
trollfredcommented, Jul 24, 2019

@jakubroztocil I would vote for this feature, using http-prompt is not always convenient

1reaction
jakubroztocilcommented, Jul 2, 2016

Have a look at https://github.com/eliangcs/http-prompt if you’re interested in this feature.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Setting baseURL in default configuration · Issue #175 - GitHub
baseURL = 'http://somesite.com'; My tests are run in Node and I want to override the baseURL so that axios will work with Nock...
Read more >
Change the default base url for axios - Stack Overflow
axios.defaults.baseURL = '/api/';. Then in my specific request, after explicitly setting the method and url, i set the baseURL to '/'
Read more >
Config Defaults | Axios Docs
You can specify config defaults that will be applied to every request. Global axios defaults. axios.defaults.baseURL = 'https://api.example ...
Read more >
Cleanly Setting Axios Base URL - YouTube
Want more? Explore the library at https://www.codecourse.comOfficial sitehttps://www.codecourse.
Read more >
38. Add Axios Default configuration like headers, base URL
In this video we will see how to add axios default configuration like headers, baseurl - Vue 3If you like my video, please...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found