URL & Routing Logic


— Soumya @Debloper Deb

Anatomy of a URL


https://www.domain.com:8080/path/page.ext?variable=value#moredata
\___/   \_______________________________/ \_____________________/
  |                     |                            |
 type            hierarchical part              dynamic data
					

foo://user:pass@domain.tld:1234/path/page.ext?var=val&i=j#unicorn
\_/   \_______________________/ \___________/ \________/  \_____/
 |                |                   |           |          |
protocol      authority            location     query    fragment
					

foo://user:pass@domain.tld:1234/path/page.ext?i=j&var=val#unicorn
      \_______/ \________/ \__/\___/ \__/ \_/     \_/ \_/ \_____/
          |         |        |   |     |   |       |   |     |
       identity  hostname  port path file type    key value hash
					

Gotta Catch 'Em All?


Explore the:

location; location; location;

Examples


Examples


Examples

The Good URL


  • Simple, short & readable
  • Predictable parameter models
  • Good location hierarchy design
  • Unique & normalized URL per content
  • Optimal usage of dynamic-parameters
  • Proper casing & serialized URL encoding

The Bad URL


  • Port, Hashbang, Index
  • Malformed dynamic-data
  • Anti-intuitive parameters
  • Forced filename extensions
  • Too long file paths & levels
  • Weird characters & delimiters

Link Shortening & Permalinks


  • Cool URIs don't change
  • [a-zA-Z0-9_-] = 26+26+10+2 = 64 options => abc.com/xx (for x in [a-zA-Z0-9_-]) Gives 64^2 = 4096 possible combinations
  • http://domain.com/<uniqueID>/human-readable-title
  • Smarter 404 pages (with prediction & redirection)

RESTful WebApps

a.k.a: I can haz teh "Clean URLs"


  • URL identifies a resource
  • Resources have proper hierarchy
  • Extensions are only useful for multi-format
  • SessionIDs, authentications aren't a part of URL
  • Nouns point to the resources, and Verbs operate on them
  • The operation requests (GET/POST/PUT/DELETE) aren't a part of the URL

So, what did we cover?


  • URL Structure & Formation
  • Parsing URL components with JavaScript
  • Salient fatures of the good & the bad URLs
  • How does URL shorteners work & how to use them
  • How web-application URLs should be schemed & designed

Thanks!


Slides: code.debs.io/talks/URL

Tweet me @Debloper


Questions?