0

As far as I understand it, the URI specification says that URIs are strings of the format scheme:b, and the format of b is specified by scheme (and there is not a finite centralised list of what scheme nor thus the formats of b can be).

So what's the point of that? Why would you want the concept of URI to exist? Why is that more useful than just the b part itself? Every technology can deal with their own b parts.

11
  • 3
    RFC 3986 seems a lot longer than what you describe to me. Oct 4, 2023 at 14:41
  • The RFC has a lot of information, but I don't think there is a good short summary of why you would choose to use a URI versus some other means to identify something. Oct 4, 2023 at 14:50
  • To provide a direct answer: the point of the URI specification is to provide a standardized way to create, parse, and interpret URIs... but I don't think that's your true question. Oct 4, 2023 at 14:53
  • 3
    The question makes sense to me - the OP is asking what value the existence of the specification provides, why people were motivated to write it and read it. I think it would be possible to give a good answer. Well known specifications don't generally exist for no reason.
    – bdsl
    Oct 4, 2023 at 17:27
  • 1
    @user1937198 it would be in the database in the Microsoft Teams column, so you just call "open MS teams with this ..." I see now why your app may sometimes want to be scheme-agnostic tho, e.g. making a calendar app, include the Join Meeting link - it could be zoom or teams and you don't want your calendar app to have to have knowledge of every meeting client that exists and how to open it
    – minseong
    Oct 4, 2023 at 18:09

4 Answers 4

8

URI's are designed to unambiguously identify a resource across different namespaces and addressing systems, like HTTP, FTP, NNTP, Gopher, email etc. Hence you need the scheme to indicate which addressing system is in use.

The idea was to connect various pre-existing information systems into a common hypertext universe. You could have a web page that had links to other web pages but also to text files hosted on FTP servers or newsgroup posts on NNTP servers.

URI's are designed to be independent of any particular file format. They should be usable in HTML as hyperlinks, but they should also be usable in plaintext, in other document formats (like Word documents), in emails, even on paper and posters.

You suggest in a comment that the scheme could be indicated through HTML attributes:

<email to="john@doe"> instead of <a href="mailto:john@doe">

This puts the scheme into the tag name rather than the URI itself, but it would only work in HTML. URI's are designed to work across different formats, even plaintext. So the scheme is made part of the URI itself.

4

The scheme for a URI provides context and meaning for how you should interpret the URI, and ultimately request the resource being identified.

The "U" in URI means "Universal" — you should be able to interpret a URI the same way whether it was embedded in a web page, or written down on a napkin passed to you in a restaurant. The href attribute of the <a> tag is a good real world example of why the scheme in a URI matters.

If the scheme is http or https, the web browser knows it can use the HTTP protocol to request that resource. If the scheme is mailto, the browser knows it should invoke the default mail client, passing the full URI. The default mail client knows that mailto:[email protected] should spawn a window allowing the end user to compose an e-mail, and the part after the : is the e-mail address that should be inserted automatically into the "To" field.

The URI itself has no behavior. The scheme is used by an application to determine if the URI is something it can process. If not, then the application might delegate this to the operating system. The part after the : is interpreted by the application as something specific to that application.

This is why http://example.com/contact.html causes a web browser to establish a socket connection to the host at example.com on port 80. Upon connecting, the browser sends HTTP/1.1 GET /contact.html to the web server, and it knows when the server responds with 404 Not Found that the browser should not attempt to request that resource again.

This is why mailto:[email protected] causes your default mail client to open a "New Message" window and populate the "To" field with "[email protected]". The application knows how to interpret that URI and do something specific with it.

Here is a fun little experiment for Microsoft Windows users.

  1. Open Windows File Explorer.
  2. Click on the location bar.
  3. Type mailto:[email protected] and press Enter.

If you have a default e-mail client, I bet the mail client spawns a "New Message" window with "[email protected]" pre-filled in the "To" field. Windows didn't do this. The Windows operating system has a catalog of which applications handle a particular URI scheme. When the operating system encounters a scheme it cannot handle, it will consult this catalog to see which application does handle that scheme. It will send a message or event to that application, and pass along the full URI. That's when your mail client recognizes the "mailto" scheme and opens a new message window.

Now try this:

  1. Open the Windows command line.
  2. Type explorer 'https://softwareengineering.stackexchange.com/' and press Enter.

I bet your default web browser opens up, bringing you back to this site.

Back in your command line, type explorer 'mailto:[email protected]' and press Enter. You get a new message window in your default mail client, don't you?

The reason to use a URI is to facilitate this flexible behavior without needing to pass instructions about how to interpret the URI. If an application can understand the URI, then great. Do something with it. If the application cannot handle a particular scheme, applications generally delegate to the operating system, where the operating system might know another application that can handle it.

2
  • Now go to your phone, and try sms:000555000 in the browser. Oct 4, 2023 at 18:37
  • 1
    @user1937198, or in your browser type 'tel:0005550000'. Oct 4, 2023 at 18:45
2

When someone hands you a bunch of ones and zeros it's nice if they tell you what to do with them.

In windows, files do this in their names after the last dot: .exe, .txt

In linux, files do this with the first line of the file with the shebang: !bash

On the internet, addresses do this with a string before a colon: http, mailto, gopher

and there is not a finite centralised list of what scheme nor thus the formats of b can be

And there never will be. Which is why anyone can add to it. Oh sure, some people keep a list but that doesn't put them in charge of this.

Anyone can tell you what to do with their ones and zeros. It's completely up to you if you want to do it.

1

You seem to be thinking about this from a very narrow viewpoint. It's a bit like me asking what the point of a prosthetic leg is given that I have all the legs I need. If you have a database or some sort of storage that you control, of course you can keep track of what the context of the location is. But that's not the point. The point is so that when you share a location with someone else, they know how to interpret it.

The context of this is the web (really hypertext.) Look at the page you are viewing this on. There are many links on it. They all happen to have the scheme of 'https' but they don't have to. If you didn't have that as part of the URL, how would the browser know what type of link it was? You would need to specify that somehow. But you don't have to because it's already a solved problem.

19
  • 1
    @theonlygusti "When do you share a location with someone else without context?" In HTML which is what the spec was created for as noted, in the answer.
    – JimmyJames
    Oct 4, 2023 at 17:54
  • 1
    "About HTML, it could have had <email to="john@doe"> instead of <a href="mailto:john@doe"> for each type of "link" a website might want." OK. Why is that better in your mind?
    – JimmyJames
    Oct 4, 2023 at 17:55
  • 2
    @theonlygusti tags works for html, but its not a general solution. What about command lines, clipboards, phone app interfaces, QR codes or sms messages? Uris provide a uniform method of specifying how to interpret the location referenced. Oct 4, 2023 at 17:58
  • 1
    Did you know you can create a QR code that will open up an SMS conversation on someones phone? Why, because QR codes contain URIs, and there is an SMS uri scheme. Oct 4, 2023 at 18:00
  • 1
    Now there is an argument for specifying that a URI is two strings, a schema and a reference, but given that in so many places it needs to be passed through locations where only a single field is available, a standard encoding is useful. Oct 4, 2023 at 18:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.