Questions tagged [uri]

A Uniform Resource Identifier (or URI) is a string of characters used to identify a name or resource. URI is legacy terminology. In most cases, the term URL should be used instead.

A Uniform Resource Identifier (or URI) is a string of characters used to identify a name or resource.

Note: The current URL Standard at https://url.spec.whatwg.org/#url-representation supersedes RFC 3986 and dispenses with the use of the term URI, as documented in its Goals section:

Standardize on the term URL. URI and IRI are just confusing. In practice a single algorithm is used for both so keeping them distinct is not helping anyone. URL also easily wins the search result popularity contest.

But the information below documents URI in terms of the legacy RFC 3986 spec.


Structure

A URI can be a Uniform Resource Locator , a Uniform Resource Name , or both.

RFC 3986 defines a URI as composed of the following parts:

    foo://example.com:8042/over/there?name=ferret#nose
    \_/   \______________/\_________/ \_________/ \__/
     |           |            |            |        |
  scheme     authority       path        query   fragment

Then defining relative URIs (Section 5.2), you can omit any of those sections, always starting from the left. In pseudo-code, it looks like this:

 result = ""

  if defined(scheme) then
     append scheme to result;
     append ":" to result;
  endif;

  if defined(authority) then
     append "//" to result;
     append authority to result;
  endif;

  append path to result;

  if defined(query) then
     append "?" to result;
     append query to result;
  endif;

  if defined(fragment) then
     append "#" to result;
     append fragment to result;
  endif;

  return result;

The URI you are describing is a scheme-less relative URI.

Examples

For example, in the following URI:

https://stackoverflow.com/questions/tagged/uri?sort=newest&pagesize=50#questions

... the components are:

  • scheme: https

  • hierarchical part: //stackoverflow.com/questions/tagged/uri

  • query: sort=newest&pagesize=50

  • fragment: questions

The precise syntax of the individual components varies depending on the scheme. Here are some examples:

  • mailto:nobody@example.com?subject=Hello&body=Is%20anybody%20home%3F

  • data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=

  • urn:ietf:rfc:3986

URL

A URL is a URI but is more specific. In addition to identifying a web resource, a URL specifies the means of acting upon or obtaining the representation, specifying both its primary access mechanism and network location.

For example, the URL http://example.org/wiki/Main_Page refers to a resource identified as /wiki/Main_Page whose representation, in the form of HTML and related code, obtainable via HyperText Transfer Protocol (http) from a network host whose domain name is example.org.

URI Reference

A URI reference may take the form of a full URI, or just the scheme-specific portion of one, or even some trailing component thereof – even the empty string. An optional fragment identifier, preceded by #, may be present at the end of a URI reference. The part of the reference before the # indirectly identifies a resource, and the fragment identifier identifies some portion of that resource.

To derive a URI from a URI reference, software converts the URI reference to 'absolute' form by merging it with an absolute 'base' URI according to a fixed algorithm. The system treats the URI reference as relative to the base URI, although in the case of an absolute reference, the base has no relevance. The base URI typically identifies the document containing the URI reference, although this can be overridden by declarations made within the document or as part of an external data transmission protocol. If the base URI includes a fragment identifier, it is ignored during the merging process. If a fragment identifier is present in the URI reference, it is preserved during the merging process.

Web document markup languages frequently use URI references to point to other resources, such as external documents or specific portions of the same logical document.

Uses of URI references in markup languages

  • In HTML, the value of the src attribute of the img element provides a URI reference, as does the value of the href attribute of the a or link element.
  • In XML, the system identifier appearing after the SYSTEM keyword in a DTD is a fragmentless URI reference.
  • In XSLT, the value of the href attribute of the xsl:import element/instruction is a URI reference; likewise the first argument to the document() function.

Examples of absolute URIs

Examples of URI references

6139 questions
4912
votes
31 answers

What is the difference between a URI, a URL, and a URN?

What is the difference between a URL, a URI, and a URN?
Sean McMains
  • 57,907
  • 13
  • 47
  • 54
1716
votes
10 answers

How are parameters sent in an HTTP POST request?

In an HTTP GET request, parameters are sent as a query string: http://example.com/page?parameter=value&also=another In an HTTP POST request, the parameters are not sent along with the URI. Where are the values? In the request header? In the request…
Camilo Martin
  • 37,236
  • 20
  • 111
  • 154
787
votes
27 answers

Should I use Singular or Plural name convention for REST resources?

Some RESTful services use different resource URIs for update/get/delete and Create. Such as Create - using /resources with POST method (observe plural) at some places using /resource (singular) Update - using /resource/123 with PUT method Get -…
JPReddy
  • 63,233
  • 16
  • 64
  • 93
724
votes
9 answers

Hyphen, underscore, or camelCase as word delimiter in URIs?

I'm designing an HTTP-based API for an intranet app. I realize it's a pretty small concern in the grand scheme of things, but: should I use hyphens, underscores, or camelCase to delimit words in the URIs? Here are my initial…
Josh Johnson
  • 8,832
  • 4
  • 25
  • 31
504
votes
29 answers

Convert file: Uri to File in Android

What is the easiest way to convert from an android.net.Uri object which holds a file: type to a java.io.File object in Android? I tried the following but it doesn't work: File file = new File(Environment.getExternalStorageDirectory(),…
hpique
  • 119,096
  • 131
  • 338
  • 476
443
votes
32 answers

Get filename and path from URI from mediastore

I have an onActivityResult returning from an mediastore image selection which I can get a URI for an image using the following: Uri selectedImage = data.getData(); Converting this to a string gives this: content://media/external/images/media/47 Or…
stealthcopter
  • 13,964
  • 13
  • 65
  • 83
359
votes
11 answers

How to check whether a string is a valid HTTP URL?

There are the Uri.IsWellFormedUriString and Uri.TryCreate methods, but they seem to return true for file paths, etc. How do I check whether a string is a valid (not necessarily active) HTTP URL for input validation purposes?
Louis Rhys
  • 34,517
  • 56
  • 153
  • 221
358
votes
33 answers

Parse a URI String into Name-Value Collection

I've got the URI like this: https://google.com.ua/oauth/authorize?client_id=SS&response_type=code&scope=N_FULL&access_type=offline&redirect_uri=http://localhost/Callback I need a collection with parsed elements: NAME …
Sergey Shafiev
  • 4,205
  • 4
  • 26
  • 37
336
votes
4 answers

What is the difference between URI, URL and URN?

What's the difference between an URI, URL and URN? I have read a lot of sites (even Wikipedia) but I don't understand it. URI: http://www.foo.com/bar.html URL: http://www.foo.com/bar.html URN: bar.html Is this correct?
thom
  • 3,371
  • 3
  • 15
  • 4
278
votes
8 answers

.NET - Get protocol, host, and port

Is there a simple way in .NET to quickly get the current protocol, host, and port? For example, if I'm on the following URL: http://www.mywebsite.com:80/pages/page1.aspx I need to return: http://www.mywebsite.com:80 I know I can use…
Jeremy
  • 3,833
  • 2
  • 22
  • 13
268
votes
24 answers

How to get Bitmap from an Uri?

How to get a Bitmap object from an Uri (if I succeed to store it in /data/data/MYFOLDER/myimage.png or file///data/data/MYFOLDER/myimage.png) to use it in my application? Does anyone have an idea on how to accomplish this?
ilredelweb
  • 3,091
  • 4
  • 17
  • 14
249
votes
8 answers

Convert String to Uri

How can I convert a String to a Uri in Java (Android)? i.e.: String myUrl = "http://stackoverflow.com"; myUri = ???;
Techboy
  • 4,286
  • 5
  • 36
  • 45
246
votes
3 answers

Turning a string into a Uri in Android

I have a string, 'songchoice'. I want it to become a 'Uri' so I can use with MediaPlayer.create(context, Uri) How can I convert songchoice to the Uri?
James Andrew
  • 7,197
  • 14
  • 46
  • 62
245
votes
8 answers

Convert file path to a file URI?

Does the .NET Framework have any methods for converting a path (e.g. "C:\whatever.txt") into a file URI (e.g. "file:///C:/whatever.txt")? The System.Uri class has the reverse (from a file URI to absolute path), but nothing as far as I can find for…
Tinister
  • 11,097
  • 6
  • 35
  • 36
1
2 3
99 100