Skip to content

Instantly share code, notes, and snippets.

@karlpokus
Last active October 13, 2016 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karlpokus/c19ca6a8df74c56a7fe54efc5c4c0d8a to your computer and use it in GitHub Desktop.
Save karlpokus/c19ca6a8df74c56a7fe54efc5c4c0d8a to your computer and use it in GitHub Desktop.
URL parts for dummies

interactive http://bl.ocks.org/abernier/3070589

node docs https://nodejs.org/api/url.html#url_url https://nodejs.org/api/http.html#http_http_request_options_callback

# protocol
http://www.foo.io/path/to/stuff?foo=bar&bar=5
^^^^-----------------------------------------

# host
http://www.foo.io:3000/path/to/stuff?foo=bar&bar=5
-------^^^^^^^^^^^^^^^----------------------------

# hostname
http://foo.io/path/to/stuff?foo=bar&bar=5
-------^^^^^^----------------------------

# port
http://www.foo.io:3000/path/to/stuff?foo=bar&bar=5
------------------^^^^----------------------------

# pathname
http://www.foo.io/path/to/stuff?foo=bar&bar=5
-----------------^^^^^^^^^^^^^^--------------

# path
http://www.foo.io/path/to/stuff?foo=bar&bar=5
-----------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^

# querystring
http://www.foo.io/path/to/stuff?foo=bar&bar=5
--------------------------------^^^^^^^^^^^^^

useful methods

// {} -> querystring
// sig: querystring.stringify(obj [, sep[, eq[, options]]])
querystring.stringify({foo: 'bar'})

// querystring -> {}
// sig: url.parse(urlString[, parseQueryString[, slashesDenoteHost]])
url.parse(url, true).query

// check incoming url in router
url.parse(url).pathname
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment