4

I'm parsing a path string containing everything after the hostname, meaning the path, query, and fragment. Previously, I was calling this whole chunk the path in a function parseUrlPath, but that's a bit confusing, since I'm calling both the inner part and the whole thing the path

Maybe it's not the worst idea... I mean, we use the word "server" for both the machine itself and the program running on that machine. But does anyone have an idea? Or even better, a reference citing an existing name for the path/query/fragment?

Chris Middleton
  • 5,654
  • 5
  • 31
  • 68

3 Answers3

6

URI.js calls the function path() for getting/setting the path and resource() for setting the part of the URI "comprising of path, query, and fragment."

Given the URI https://user@example.com:8080/foo/bar.html?q=3#baz:

path() === '/foo/bar.html'
query() === 'q=3'
resource() === '/foo/bar.html?q=3#baz'

This might be useful: https://medialize.github.io/URI.js/docs.html

rink.attendant.6
  • 44,500
  • 61
  • 101
  • 156
0

I kept saying "relative to the domain" to myself without realizing that was the answer.

A good name for such a function would be parseHostnameRelativeUrl or simply parseRelativeUrl if it's understood that the hostname is what we are always relative to.

Source for idea: https://stackoverflow.com/a/2005174/2407870

* Technically, it would be parseAuthorityRelativeUrl, since the "authority" part includes from the user info up to the path, but no one would understand that.

Community
  • 1
  • 1
Chris Middleton
  • 5,654
  • 5
  • 31
  • 68
0

The well-known parts are: protocol, hostname (service name + second-level domain name + top-level domain name), directory name or major category, sub-directory or sub category, filename, file extension, and finally followed by parameters. Only the protocol and hostname are mandatory though modern apps may provide defaults or search engine lookups when something's missing.

Emacs User
  • 1,457
  • 1
  • 12
  • 19