Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Uri::toRelative(base: Uri): Uri method #99

Open
akka-ci opened this issue Sep 8, 2016 · 3 comments
Open

Add Uri::toRelative(base: Uri): Uri method #99

akka-ci opened this issue Sep 8, 2016 · 3 comments
Labels
1 - triaged Tickets that are safe to pick up for contributing in terms of likeliness of being accepted help wanted Identifies issues that the core team will likely not have time to work on nice-to-have (low-prio) Tasks which make sense, however are not very high priority, feel free to help out!
Milestone

Comments

@akka-ci
Copy link

akka-ci commented Sep 8, 2016

Issue by bblfish
Friday Jul 04, 2014 at 09:08 GMT
Originally opened as akka/akka#15495


I reported this as Spray issue 818 as the move to akka was underway. So I'll add a reference here.

Currently one can make a Uri relative to the root.

**
   * Converts this URI into a relative URI by keeping the path, query and fragment, but dropping the scheme and authority.
   */
  def toRelative =
    Uri(path = if (path.isEmpty) Uri.Path./ else path, query = query, fragment = fragment)

It would be useful to have the same functionality as java.net.URI#relativize(URI) to allow easy relative URI creation.

scala> import java.net.URI
import java.net.URI

scala> val card = new URI("http://bblfish.net/people/henry/card#me")
card: java.net.URI = http://bblfish.net/people/henry/card#me

scala> val base1 = new URI("http://bblfish.net/people/")
base1: java.net.URI = http://bblfish.net/people/

scala> base1.relativize(card)
res0: java.net.URI = henry/card#me

scala> new URI("http://bblfish.net/people/henry/").relativize(card)
res1: java.net.URI = card#me

scala> new URI("http://bblfish.net/people/henry/card").relativize(card)
res2: java.net.URI = #me

It is often very useful to serialise to relative uris when a base is known. So when one does a GET on
a URI such as http://bblfish.net/people/henry/card it is much easier to read the result when it says

<> a foaf:PersonalProfileDocument;
    foaf:primaryTopic <card> .

rather than writing out all the Uris in full. Because a relative URI such as "" ( or <> and in the above ) allows a human to immediatly understand that the document is speaking of itself. A full URI requires a human to do a full comparison.

So we need this a lot in serialisations. Having this feature would allow banana-rdf for example to move totally to akka-http, which would also make it easier then to write code that can compile with scala-js.

As a matter of interest I wonder if it would be possible to make type distinctions between full and relative Uris. (Full Uris being a subclass of relative Uris perhaps). This would help make a large class of errors visible to the compiler, as explained in issue #41 of banana-rdf. Perhaps that should be for a different bug report?

@akka-ci akka-ci added this to the http-backlog milestone Sep 8, 2016
@akka-ci akka-ci added help wanted Identifies issues that the core team will likely not have time to work on nice-to-have (low-prio) Tasks which make sense, however are not very high priority, feel free to help out! t:http labels Sep 8, 2016
@akka-ci
Copy link
Author

akka-ci commented Sep 8, 2016

Comment by patriknw
Wednesday Aug 06, 2014 at 14:17 GMT


@sirthias have you seen this?

@akka-ci
Copy link
Author

akka-ci commented Sep 8, 2016

Comment by sirthias
Thursday Aug 07, 2014 at 09:26 GMT


Apparently I have sometime in March but I have to admit that I don't remember.
I think this is a valid feature request, whose implementation should be relatively contained and not hard to do.

@akka-ci
Copy link
Author

akka-ci commented Sep 8, 2016

Comment by jrudolph
Friday Jun 05, 2015 at 15:12 GMT


This is nice to have but not a http:next feature.

@ktoso ktoso closed this as completed Sep 8, 2016
@ktoso ktoso reopened this Sep 8, 2016
@ktoso ktoso added 1 - triaged Tickets that are safe to pick up for contributing in terms of likeliness of being accepted and removed t:http labels Sep 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1 - triaged Tickets that are safe to pick up for contributing in terms of likeliness of being accepted help wanted Identifies issues that the core team will likely not have time to work on nice-to-have (low-prio) Tasks which make sense, however are not very high priority, feel free to help out!
Projects
None yet
Development

No branches or pull requests

2 participants