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.

Append path to Uri

See original GitHub issue

The 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:closed
  • Created 6 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
reactormonkcommented, Jun 2, 2017

Or overload / to take another Path object, that way you can construct the Path however you want.

0reactions
Laseringcommented, May 25, 2020
Read more comments on GitHub >

github_iconTop 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 >

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