@@ -179,7 +179,7 @@ The first computer sends a **request** for some data and the second computer **r
179179---
180180
181181<span class =" centered " >
182- <img src =" Request Response.png " />
182+ <img src =" assets/ Request Response.png" />
183183</span >
184184
185185---
@@ -487,3 +487,281 @@ print_greeting(name=name_to_greet)
487487```
488488
489489---
490+
491+ # URLs and routing
492+
493+ ---
494+
495+ ## URLs and routing
496+
497+ <span class =" center narrow " >
498+
499+ Let's breakdown what URLs are, how they work, and how they are used to navigate ** to** and ** within** our Flask applications.
500+
501+ </span >
502+
503+ ---
504+
505+ ## Let's start with definitions
506+
507+ <span class =" center wide " >
508+
509+ ** URL** : an acronym for Uniform Resource Locator, URLs are the "address" of a resource (a webpage, a video, a photo, etc.) This resource can be in our own computer, or on another computer.
510+
511+ </span >
512+
513+ ---
514+
515+ ## URLs are addresses
516+
517+ URLs are addresses and they help us navigate The Internet to find and access a resource.
518+
519+ ---
520+
521+ ## URLs are addresses
522+
523+ By typing a URL into our browser's address bar, we send a request to the web server asking for what we need and it will response with the image/video/HTML/etc. that we asked for.
524+
525+ ---
526+
527+ <span class =" centered " >
528+ <img src =" assets/Request Response.png " />
529+ </span >
530+
531+ ---
532+
533+ A web server is a program that is able to accept these requests and response appropriately.
534+
535+ ---
536+
537+ Our Flask applications are web servers.
538+
539+ ---
540+
541+ ## Example URLs
542+
543+ <span class =" centered " >
544+
545+ - https://www.google.com
546+ - https://www.youtube.com/watch?v=Z1RJmh_OqeA
547+ - https://en.wikipedia.org/wiki/Computer_programming#Programming_languages
548+ - https://upload.wikimedia.org/wikipedia/commons/d/df/The_Fabs.JPG
549+
550+ </span >
551+
552+ ---
553+
554+ <!-- _footer: 'Unit 3: Introduction to Flask (image source: https://developer.mozilla.org/en-US/docs/Learn/Common_questions/Web_mechanics/What_is_a_URL' -->
555+
556+ <span class =" centered " >
557+ <img src =" assets/mdn-url-all.png " />
558+ </span >
559+
560+ ---
561+
562+ ## Scheme
563+
564+ <div class =" ws-nw fs7 code " >
565+ <span class =" highlight bold " >http</span >://www.example.com:80/path/to/myfile.html?key1=value1&key2=value2#SomewhereInTheDocument
566+ </div >
567+
568+ <hr />
569+
570+ The scheme indicates the protocol that must be used when talking to the server. This of a protocol as the "language" that must be used.
571+
572+ ---
573+
574+ ## Domain
575+
576+ <div class =" ws-nw fs7 code " >
577+ http://<span class =" highlight bold " >www.example.com</span >:80/path/to/myfile.html?key1=value1&key2=value2#SomewhereInTheDocument
578+ </div >
579+
580+ <hr />
581+
582+ The domain is the address for the web server that we are trying to reach.
583+
584+ ---
585+
586+ ## Domain (IP address)
587+
588+ <div class =" ws-nw fs7 code " >
589+ http://<span class =" highlight bold " >159.89.240.57</span >:80/path/to/myfile.html?key1=value1&key2=value2#SomewhereInTheDocument
590+ </div >
591+
592+ <hr />
593+
594+ <span class =" center wide " >
595+
596+ Since a domain corresponds to an IP address, An IP address may be used in place of the domain.
597+
598+ </span >
599+
600+ ---
601+
602+ ## Domain (local IP address)
603+
604+ <div class =" ws-nw fs7 code " >
605+ http://<span class =" highlight bold " >127.0.0.1</span >:80/path/to/myfile.html?key1=value1&key2=value2#SomewhereInTheDocument
606+ </div >
607+
608+ <hr />
609+
610+ <span class =" center wide " >
611+
612+ ` 127.0.0.1 ` is the IP address for your local computer.
613+
614+ </span >
615+
616+ ---
617+
618+ ## Domain (localhost)
619+
620+ <div class =" ws-nw fs7 code " >
621+ http://<span class =" highlight bold " >localhost</span >:80/path/to/myfile.html?key1=value1&key2=value2#SomewhereInTheDocument
622+ </div >
623+
624+ <hr />
625+
626+ <span class =" center wide " >
627+
628+ ` localhost ` is a special domain that corresponds to your local computer as well.
629+
630+ </span >
631+
632+ ---
633+
634+ <!-- _footer: 'Unit 3: Introduction to Flask ([1] text source: https://developer.mozilla.org/en-US/docs/Learn/Common_questions/Web_mechanics/What_is_a_URL#authority' -->
635+
636+ ## Port
637+
638+ <div class =" ws-nw fs7 code " >
639+ http://www.example.com :<span class =" highlight bold " >80</span >/path/to/myfile.html?key1=value1&key2=value2#SomewhereInTheDocument
640+ </div >
641+
642+ <hr />
643+
644+ <span class =" center wide " >
645+
646+ The port indicates the technical "gate" used to access the resources on the web server. It is usually omitted if the web server uses the standard ports of the HTTP protocol (80 for HTTP and 443 for HTTPS) to grant access to its resources. <span class =" fs6 code " >[ 1] </span >
647+
648+ </span >
649+
650+ ---
651+
652+ ## Path
653+
654+ <div class =" ws-nw fs7 code " >
655+ http://www.example.com:80 <span class =" highlight bold " >/path/to/myfile.html</span >?key1=value1&key2=value2#SomewhereInTheDocument
656+ </div >
657+
658+ <hr />
659+
660+ <span class =" center wide " >
661+
662+ The path corresponds to the path or route of the resource on the web server.
663+
664+ </span >
665+
666+ ---
667+
668+ ## Path
669+
670+ <div class =" ws-nw fs7 code " >
671+ http://www.example.com:80 <span class =" highlight bold " >/path/to/myfile.html</span >?key1=value1&key2=value2#SomewhereInTheDocument
672+ </div >
673+
674+ <hr />
675+
676+ <span class =" center wide " >
677+
678+ In Flask, this is what we use ` @app.route ` for.
679+
680+ </span >
681+
682+ ---
683+
684+ ## Path
685+
686+ <div class =" ws-nw fs7 code " >
687+ http://www.example.com:80 <span class =" highlight bold " >/path/to/myfile.html</span >?key1=value1&key2=value2#SomewhereInTheDocument
688+ </div >
689+
690+ <div class =" ws-nw fs7 code mt1 " >
691+ http://www.example.com:80 <span class =" highlight bold " >/more</span >?key1=value1&key2=value2#SomewhereInTheDocument
692+ </div >
693+
694+ <hr />
695+
696+ <span class =" center wide " >
697+
698+ Paths may have multiple parts, each separated by a forward slash.
699+
700+ </span >
701+
702+ ---
703+
704+ ## Path
705+
706+ <div class =" ws-nw fs7 code " >
707+ http://www.example.com:80 <span class =" highlight bold " >/</span >?key1=value1&key2=value2#SomewhereInTheDocument
708+ </div >
709+
710+ <hr />
711+
712+ ` / ` is the default path. When you see a URL without a path, it'll default to this. This path is referred to as the "index" path.
713+
714+ ---
715+
716+ ## Parameters
717+
718+ <div class =" ws-nw fs7 code " >
719+ http://www.example.com:80/path/to/myfile.html <span class =" highlight bold " >?key1=value1&key2=value2</span >#SomewhereInTheDocument
720+ </div >
721+
722+ <hr />
723+
724+ These are extra parameters (information) that is provided to the web server. These parameters are a list of key / value pairs (like a dictionary in Python) separated by ` & ` .
725+
726+ ---
727+
728+ ## Anchor
729+
730+ <div class =" ws-nw fs7 code " >
731+ http://www.example.com:80/path/to/myfile.html?key1=value1&key2=value2 <span class =" highlight bold " >#SomewhereInTheDocument</span >
732+ </div >
733+
734+ <hr />
735+
736+ This is an anchor to a section in the webpage returned by the web server. This is used by browsers to scroll right to that section in the webpage.
737+
738+ ---
739+
740+ <!-- _footer: 'Unit 3: Introduction to Flask (image source: https://developer.mozilla.org/en-US/docs/Learn/Common_questions/Web_mechanics/What_is_a_URL' -->
741+
742+ <span class =" centered " >
743+ <img src =" assets/mdn-url-all.png " />
744+ </span >
745+
746+ <span class =" centered widest mt1 " >
747+
748+ - The ** scheme** is used to determine which language to use when talking with the web server.
749+ - The ** domain name** is used to reach the web server.
750+ - The ** port** is used to pick the correct entry into the web server.
751+ - The ** path** and ** parameters** are for the web server to use for whatever it wants.
752+ - The ** anchor** is used by the browser to scroll to the correct position.
753+
754+ </span >
755+
756+ ---
757+
758+ ## How do URLs relate to Flask applications?
759+
760+ <span class =" centered widest mt1 " >
761+
762+ - The ** scheme** , ** domain name** , and ** port** are used to reach the web server.
763+ - The ** path** is used by the web server (your Flask application) to determine what action it should perform and how it should respond.
764+
765+ </span >
766+
767+ ---
0 commit comments