{"action":"opened","issue":{"url":"https://api.github.com/repos/kennethreitz/requests/issues/2554","labels_url":"https://api.github.com/repos/kennethreitz/requests/issues/2554/labels{/name}","comments_url":"https://api.github.com/repos/kennethreitz/requests/issues/2554/comments","events_url":"https://api.github.com/repos/kennethreitz/requests/issues/2554/events","html_url":"https://github.com/kennethreitz/requests/issues/2554","id":69869660,"number":2554,"title":"Ability to prefix session URLs","user":{"login":"foxx","id":651797,"avatar_url":"https://avatars.githubusercontent.com/u/651797?v=3","gravatar_id":"","url":"https://api.github.com/users/foxx","html_url":"https://github.com/foxx","followers_url":"https://api.github.com/users/foxx/followers","following_url":"https://api.github.com/users/foxx/following{/other_user}","gists_url":"https://api.github.com/users/foxx/gists{/gist_id}","starred_url":"https://api.github.com/users/foxx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/foxx/subscriptions","organizations_url":"https://api.github.com/users/foxx/orgs","repos_url":"https://api.github.com/users/foxx/repos","events_url":"https://api.github.com/users/foxx/events{/privacy}","received_events_url":"https://api.github.com/users/foxx/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-04-21T14:57:39Z","updated_at":"2015-04-21T14:57:39Z","closed_at":null,"body":"It would be nice to be able to prefix session URLs to avoid repetitive code.\r\n\r\nConsider the following code;\r\n\r\n```\r\nfrom requests import Session\r\nclass MyTestCase(LiveServerTestCase):\r\n    def test_url(self):\r\n        s = Session()\r\n        s.get(\"{}/api/people'.format(self.server_url))\r\n        s.get(\"{}/api/cats'.format(self.server_url))\r\n```\r\n\r\nThis could look a lot prettier by doing;\r\n\r\n```\r\nfrom requests import Session\r\nclass MyTestCase(LiveServerTestCase):\r\n    def test_url(self):\r\n        s = Session(prefix_url='http://example.com')\r\n        s.get('/api/people')\r\n        s.get('/api/cats')\r\n```\r\n\r\nIn the mean time, I was able to achieve this by using a subclass;\r\n\r\n```\r\nclass Session(requests.Session):\r\n    \"\"\"Helpers for performing API queries\"\"\"\r\n    def __init__(self, *args, **kwargs):\r\n        self.prefix_url = kwargs.get('prefix_url', None)\r\n        super(Session, self).__init__(*args, **kwargs)\r\n\r\n    def request(self, method, url, *args, **kwargs):\r\n        if self.prefix_url:\r\n            url = \"{}{}\".format(self.prefix_url, url)\r\n        return super(Session, self).request(method, url, *args, **kwargs)\r\n```\r\n\r\n@kennethreitz would such a PR be accepted?"}}