Append path to Uri
See original GitHub issueThe current method /
on Uri
appends the new segment by first URL encoding it. This is very useful, for example, to append a user name to the path:
> Uri.uri("https://localhost/api/rest/users") / "Simão Martins"
res25: Uri = Uri(Some(https), Some(Authority(None, RegName(localhost), None)), "/api/rest/users/Sim%C3%A3o%20Martins", Query(), None)
However if we want to construct a new Uri from a base Uri, for example: :
> val baseUri = Uri.uri("https://localhost/api/v1")
baseUri: Uri = Uri(Some(https), Some(Authority(None, RegName(localhost), None)), "/api/v1", Query(), None)
> baseUri / "/users/scripts/"
res27: Uri = Uri(Some(https), Some(Authority(None, RegName(localhost), None)), "/api/v1/%2Fusers%2Fscripts%2F", Query(), None)
We do not get what we wanted (https://localhost/api/v1/users/scripts/
).
An additional method, which does not perform URL encode, should exist. Something like:
def +/(extraPath: String): Uri = {
(uri.path.last == '/', extraPath.last == '/') match {
case (false, true) | (true, false) => uri.withPath(s"${uri.path}$extraPath")
case (false, false) => uri.withPath(s"${uri.path}/$extraPath")
case (true, true) => uri.withPath(s"${uri.path}${extraPath.substring(1)}")
}
}
Or maybe an overloaded version of /
which receives an additional parameter urlEncode: Boolean
.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Path.Combine for URLs?
Uri has a constructor that should do this for you: new Uri(Uri baseUri, ... static Uri Append(this Uri uri, params string[] paths) {...
Read more >how to combine URL-type strings in ASP.NET ...
The Path.Combine method, available in all ASP.NET programming languages, is a great way to combine multiple strings into a valid File System ...
Read more >How to combine URLs/URIs in C#
The file system have the Path.Combine method to combine paths but how to combine a base URL with an absolute or relative URL/URI?...
Read more >Add query and path parameters to the URI
To add a path parameter to a URI object, use AddPathSegment() : oURI = new URI('http', 'oemobiledemo.progress.com'). oURI:Path = "/ ...
Read more >UriBuilder.Path Property (System)
The path information does not include the scheme, host name, or query portion of the URI. The Path property always returns at least...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Or overload
/
to take anotherPath
object, that way you can construct thePath
however you want.This is already solved by the addPath method on Uri https://http4s.org/v0.21/api/org/http4s/uri#addPath(morePath:org.http4s.Uri.Path):org.http4s.Uri