Title: idiomatic way to extend paths · Issue #48 · python-hyper/hyperlink · GitHub
Open Graph Title: idiomatic way to extend paths · Issue #48 · python-hyper/hyperlink
X Title: idiomatic way to extend paths · Issue #48 · python-hyper/hyperlink
Description: it seems hyperlink does not have a nice way to add path components to a base url, which is a very common operation when interacting with rest apis. for example, consider >>> from hyperlink import URL >>> base_url = URL.from_text('https:/...
Open Graph Description: it seems hyperlink does not have a nice way to add path components to a base url, which is a very common operation when interacting with rest apis. for example, consider >>> from hyperlink import U...
X Description: it seems hyperlink does not have a nice way to add path components to a base url, which is a very common operation when interacting with rest apis. for example, consider >>> from hyperlink...
Opengraph URL: https://github.com/python-hyper/hyperlink/issues/48
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"idiomatic way to extend paths","articleBody":"it seems `hyperlink` does not have a nice way to add path components to a base url, which is a very common operation when interacting with rest apis.\r\n\r\nfor example, consider\r\n\r\n``` python\r\n>>> from hyperlink import URL\r\n>>> base_url = URL.from_text('https://example.org/api/v2')\r\n```\r\n\r\nlet's assume i want to build a url for an endpoint below this base url, e.g. `users/search`.\r\n\r\nthis works:\r\n\r\n``` python\r\n>>> base_url.replace(path=base_url.path + ('users', 'search'))\r\nURL.from_text('https://example.org/api/v2/users/search')\r\n```\r\n\r\n... but let's face it, this is not so nice:\r\n\r\n- `users/search` (likely copied from some documentation) needs manual splitting into a tuple\r\n- `base_url` is referenced twice since the `.path` tuple is required for the concatenation\r\n\r\nmaking this nicer is not really possible with the current api. for example:\r\n\r\n``` python\r\n>>> base_url.replace(path=base_url.path + 'users/search'.split('/'))\r\n[...]\r\nTypeError: can only concatenate tuple (not \"list\") to tuple\r\n```\r\n\r\noops. well, that's easy to work around:\r\n\r\n``` python\r\n>>> base_url.replace(path=base_url.path + tuple('users/search'.split('/')))\r\nURL.from_text('https://example.org/api/v2/users/search')\r\n```\r\n\r\n...but the end result is even uglier.\r\n\r\nit would be great if a use case like this is handled with a nicer api. thoughts?\r\n\r\n","author":{"url":"https://github.com/wbolster","@type":"Person","name":"wbolster"},"datePublished":"2017-11-16T12:22:52Z","url":"https://github.com/python-hyper/hyperlink/issues/48"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:f50cd59a-3c60-a549-de1b-2bd46629fb0a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D126:2BA984:60AC4:84790:6B06F3BA |
| html-safe-nonce | bc67a6cfdc5cef20aeccf4d50146e53b61bbe0368144430be2acfbac7c23375f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMTI2OjJCQTk4NDo2MEFDNDo4NDc5MDo2QjA2RjNCQSIsInZpc2l0b3JfaWQiOiI1NTMzMTE4Njc0NTkwMTY3OTk0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 19dc3be760d4308f00800dd714a464159b143dfd50c4b2142a718e01428facdd |
| hovercard-subject-tag | issue:274497226 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python-hyper/hyperlink/48/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7ae9f7e638895e83c770009856817c985debf4353e1ef08cd4993b91a9349043/python-hyper/hyperlink/issues/48 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7ae9f7e638895e83c770009856817c985debf4353e1ef08cd4993b91a9349043/python-hyper/hyperlink/issues/48 |
| og:image:alt | it seems hyperlink does not have a nice way to add path components to a base url, which is a very common operation when interacting with rest apis. for example, consider >>> from hyperlink import U... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | wbolster |
| hostname | github.com |
| expected-hostname | github.com |
| None | 351ea5ca38a5758919d44ee52c70fe9003c0c2dfa20f04effd7fac0c5330c16b |
| turbo-cache-control | no-preview |
| go-import | github.com/python-hyper/hyperlink git https://github.com/python-hyper/hyperlink.git |
| octolytics-dimension-user_id | 13035907 |
| octolytics-dimension-user_login | python-hyper |
| octolytics-dimension-repository_id | 82321340 |
| octolytics-dimension-repository_nwo | python-hyper/hyperlink |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 82321340 |
| octolytics-dimension-repository_network_root_nwo | python-hyper/hyperlink |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 891bde3f438884e9c6c7ccd826f33805910a978b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width