intro webapps

10

Click here to load reader

Upload: howard-mao

Post on 12-Jul-2015

143 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Intro webapps

Building Dynamic Web Applications

Howie Mao

May 2, 2013

Page 2: Intro webapps

Clients and Servers

I The web runs on a client-server modelI A server is a program that listens on a network for requests

and services the requests. A webserver is a server that sendswebpages as its service.

I A client is a program that requests services from the server.Your web browser is an example of a client.

Page 3: Intro webapps

How to write a server?

I Server calls attaches itself to a port and starts listening forconnections

I Each computer has many ports (literally numbers from 1 to65535) allowing internet traffic to be delivered to the correctserver even if there are multiple servers on the same computer

I A client connects to a server by specifying its address and port

Page 4: Intro webapps

What happens when I go to a website

I Web browser (client) connects to webserver (usually on port80)

I Web browser sends an HTTP request, asking for a certainresource

I Server sends an HTTP response, consisting of a header, whichcontains metadata about the resource being sent, followed bythe data for the resource itself (a web page) in the body.

Page 5: Intro webapps

Web Frameworks

I For making web applications, you probably want more thanjust a socket library

I You use a web framework, which provides you with the utilitiesto deal with HTTP requests and other parts of a website

I In this talk, we will use Flask, a very simple framework forPython

Page 6: Intro webapps

Routing URLs

I The key function of any web frameworkI Takes a URL and decides what code to runI Can also use parts of the URL as data

Page 7: Intro webapps

Templating

I Makes it easier to generate HTML (or anything else) usingchanging data.

I Key concepts are inheritance and substitution.

Page 8: Intro webapps

Databases

I Allows for efficient storage and retrieval of user data.I Many different kinds of databases.I Relational, document-oriented, key-value, graph-based, etc.I Choice of database depends on type of data stored

Page 9: Intro webapps

Sessions and Cookies

I Allows users to stay "logged in".I Server sends browser a cookie, a piece of data which the

browser stores locally.I When the site is revisited, the cookie is sent back to the server.I This tells server the user is logged in already.I Cookies can be given an expiration time, or can be told to

expire once browser is closed.

Page 10: Intro webapps

Security

I Encrypt cookies used to store login infoI Login credentials and session cookies should be sent in

HTTPS (encrypted HTTP).I Passwords should be hashed before storing in database.I Always escape user input before storing in a database or

putting in a template.