Building Dynamic Web Applications
Howie Mao
May 2, 2013
Clients and Servers
The web runs on a client-server model
A server is a program that listens on a network for requests
and services the requests. A webserver is a server that sends
webpages as its service.
A client is a program that requests services from the server.
Your web browser is an example of a client.
How to write a server?
Server calls attaches itself to a port and starts listening for
connections
Each computer has many ports (literally numbers from 1 to
65535) allowing internet traffic to be delivered to the correct
server even if there are multiple servers on the same computer
A client connects to a server by specifying its address and port
What happens when I go to a website
Web browser (client) connects to webserver (usually on port
80)
Web browser sends an HTTP request, asking for a certain
resource
Server sends an HTTP response, consisting of a header, which
contains metadata about the resource being sent, followed by
the data for the resource itself (a web page) in the body.
Web Frameworks
For making web applications, you probably want more than
just a socket library
You use a web framework, which provides you with the utilities
to deal with HTTP requests and other parts of a website
In this talk, we will use Flask, a very simple framework for
Python
Routing URLs
The key function of any web framework
Takes a URL and decides what code to run
Can also use parts of the URL as data
Templating
Makes it easier to generate HTML (or anything else) using
changing data.
Key concepts are inheritance and substitution.
Databases
Allows for efficient storage and retrieval of user data.
Many different kinds of databases.
Relational, document-oriented, key-value, graph-based, etc.
Choice of database depends on type of data stored
Sessions and Cookies
Allows users to stay "logged in".
Server sends browser a cookie, a piece of data which the
browser stores locally.
When the site is revisited, the cookie is sent back to the server.
This tells server the user is logged in already.
Cookies can be given an expiration time, or can be told to
expire once browser is closed.
Security
Encrypt cookies used to store login info
Login credentials and session cookies should be sent in
HTTPS (encrypted HTTP).
Passwords should be hashed before storing in database.
Always escape user input before storing in a database or
putting in a template.

Intro webapps

  • 1.
    Building Dynamic WebApplications Howie Mao May 2, 2013
  • 2.
    Clients and Servers Theweb runs on a client-server model A server is a program that listens on a network for requests and services the requests. A webserver is a server that sends webpages as its service. A client is a program that requests services from the server. Your web browser is an example of a client.
  • 3.
    How to writea server? Server calls attaches itself to a port and starts listening for connections Each computer has many ports (literally numbers from 1 to 65535) allowing internet traffic to be delivered to the correct server even if there are multiple servers on the same computer A client connects to a server by specifying its address and port
  • 4.
    What happens whenI go to a website Web browser (client) connects to webserver (usually on port 80) Web browser sends an HTTP request, asking for a certain resource Server sends an HTTP response, consisting of a header, which contains metadata about the resource being sent, followed by the data for the resource itself (a web page) in the body.
  • 5.
    Web Frameworks For makingweb applications, you probably want more than just a socket library You use a web framework, which provides you with the utilities to deal with HTTP requests and other parts of a website In this talk, we will use Flask, a very simple framework for Python
  • 6.
    Routing URLs The keyfunction of any web framework Takes a URL and decides what code to run Can also use parts of the URL as data
  • 7.
    Templating Makes it easierto generate HTML (or anything else) using changing data. Key concepts are inheritance and substitution.
  • 8.
    Databases Allows for efficientstorage and retrieval of user data. Many different kinds of databases. Relational, document-oriented, key-value, graph-based, etc. Choice of database depends on type of data stored
  • 9.
    Sessions and Cookies Allowsusers to stay "logged in". Server sends browser a cookie, a piece of data which the browser stores locally. When the site is revisited, the cookie is sent back to the server. This tells server the user is logged in already. Cookies can be given an expiration time, or can be told to expire once browser is closed.
  • 10.
    Security Encrypt cookies usedto store login info Login credentials and session cookies should be sent in HTTPS (encrypted HTTP). Passwords should be hashed before storing in database. Always escape user input before storing in a database or putting in a template.