web programming week 2

26
Web Programming Week 2 Old Dominion University Department of Computer Science CS 418/518 Fall 2010 Martin Klein <[email protected]> 09/07/10

Upload: ainsley-odom

Post on 04-Jan-2016

38 views

Category:

Documents


4 download

DESCRIPTION

Web Programming Week 2. Old Dominion University Department of Computer Science CS 418/518 Fall 2010 Martin Klein 09/07/10. Defining the Web / HTTP. HTTP was originally defined by Request for Comments (RFCs)1945, 2068, 2616 - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Web Programming Week 2

Web Programming

Week 2

Old Dominion UniversityDepartment of Computer Science

CS 418/518 Fall 2010

Martin Klein <[email protected]>

09/07/10

Page 2: Web Programming Week 2

Defining the Web / HTTP• HTTP was originally defined by Request for

Comments (RFCs)1945, 2068, 2616– and several others for defining URLs, URIs, etc.

• While RFC 2616 remains canonical for HTTP, we have a new document for the “Web” (URIs + protocols + formats), we have a slightly revisionist but ultimately useful unifying document:– The Architecture of the World Wide Web, Volume

One.• http://www.w3.org/TR/webarch/

Page 3: Web Programming Week 2

How To Read RFCs

(quoting from RFC 2119)

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.

1. MUST This word, or the terms "REQUIRED" or "SHALL", mean that the definition is an absolute requirement of the specification.

2. MUST NOT This phrase, or the phrase "SHALL NOT", mean that the definition is an absolute prohibition of the specification.

3. SHOULD This word, or the adjective "RECOMMENDED", mean that there may exist valid reasons in particular circumstances to ignore a particular item, but the full implications must be understood and carefully weighed before choosing a different course.

4. SHOULD NOT This phrase, or the phrase "NOT RECOMMENDED" mean that there may exist valid reasons in particular circumstances when the particular behavior is acceptable or even useful, but the full implications should be understood and the case carefully weighed before implementing any behavior described with this label.

5. MAY This word, or the adjective "OPTIONAL", mean that an item is truly optional. One vendor may choose to include the item because a particular marketplace requires it or because the vendor feels that it enhances the product while another vendor may omit the same item. An implementation which does not include a particular option MUST be prepared to interoperate with another implementation which does include the option, though perhaps with reduced functionality. In the same vein an implementation which does include a particular option MUST be prepared to interoperate with another implementation which does not include the option (except, of course, for the feature the option provides.)

Page 4: Web Programming Week 2

Examples from RFC 261610.4.6

405 Method Not Allowed

The method specified in the Request-Line is not allowed for the resource identified by the Request-URI. The response MUST include an Allow header containing a list of valid methods for the requested resource.

10.4.4

403 Forbidden

The server understood the request, but is refusing to fulfill it. Authorization will not help and the request SHOULD NOT be repeated.

10.4.9

408 Request Timeout

The client did not produce a request within the time that the server was prepared to wait. The client MAY repeat the request without modifications at any later time.

Page 5: Web Programming Week 2

Reading the W3C Arch

• Principles– fundamental “rule” or “law” that is widely applicable

• Constraints– definitions imposed by the architects of the Web– “MUST”, “SHALL”

• Good Practice– things you should be doing, but they can’t / shouldn’t

be defined as constraints – “SHOULD”, “RECOMMENDED”

Page 6: Web Programming Week 2

Principle: Global Identifiers

• Principle: Global Identifiers– Global naming leads to global network effects.

Page 7: Web Programming Week 2

Good practice: Identify with URIs

• Good practice: Identify with URIs– To benefit from and increase the value of the

World Wide Web, agents should provide URIs as identifiers for resources.

Page 8: Web Programming Week 2

Constraint: URIs Identify a Single Resource

• Constraint: URIs Identify a Single Resource– Assign distinct URIs to distinct resources.

Page 9: Web Programming Week 2

Uniform Resource Identifiers

URI

URL URN

RFC 3986 (2396)

RFC 2141RFC 1738

Page 10: Web Programming Week 2

URI Schemes

foo://username:[email protected]:8042/over/there/index.dtb;type=animal?name=ferret#nose \ / \________________/\_________/ \__/ \___/ \_/ \_________/ \_________/ \__/ | | | | | | | | | | userinfo hostname port | | parameter query fragment | \_______________________________/ \_____________|____|____________/scheme | | | | | authority |path| | | | | path interpretable as filename | ___________|____________ | / \ / \ | urn:example:animal:ferret:nose interpretable as extension

taken from: http://en.wikipedia.org/wiki/URI_scheme

Page 11: Web Programming Week 2

remember: • URIs identify Resources• Representations represent Resources• When URIs are dereferenced, they return representations (i.e., a resource is never returned)

taken from: http://www.w3.org/TR/webarch/

Important Web Architecture Concepts (As defined by the Web Architecture)

Page 12: Web Programming Week 2

W3C Web Architecture

Resource

URIRepresentation 2

Represents

Representation 1

Represents

Identifies

Content Negotiation

The tools we have to solve the interoperability problem are:

• Resource• URI• Representation

slide from Herbert Van de Sompel

Page 13: Web Programming Week 2
Page 14: Web Programming Week 2

LAMP

• Chapters 3, 10 of textbook– more info: http://dev.mysql.com/doc/

• Quick review of relational databases– normalization– referential integrity

• Basic MySQL commands

Page 15: Web Programming Week 2

“Graphic Novel” Super Heroes (from chapter 10)

name real name

power 1 power 2 power 3 lair address

city state zip

Clean Freak

John Smith

Strength X-ray vision

flight 123 Poplar Ave

Townsburg OH 45293

Soap Stud Efram Jones

Speed 123 Poplar Ave

Townsburg OH 45293

The Dustmite

Dustin Huff

Strength Dirtiness Laser Vision

452 Elm St. #3D

Burgtown OH 45201

What if we need to add a super hero with more than 3 powers?

Page 16: Web Programming Week 2

1st Normal Form

• Eliminate repeating columns

• Add primary key to table– Unique– Must not change

• Maintain “atomicity“– Each cell is atomic, has only one item of data

Page 17: Web Programming Week 2

1NF• add primary key to tables

• eliminate repeating columns

• each attribute is atomic

id name realname

power lairaddress

city state zip

1 CleanFreak

JohnSmith

Strength 123PoplarAve

Townsburg OH 45293

1 CleanFreak

JohnSmith

X-rayvision

123PoplarAve

Townsburg OH 45293

1 CleanFreak

JohnSmith

flight 123PoplarAve

Townsburg OH 45293

2 SoapStud

EframJones

Speed 123PoplarAve

Townsburg OH 45293

3 TheDustmite

DustinHuff

Strength 452Elm St.#3D

Burgtown OH 45201

3 TheDustmite

DustinHuff

Dirtiness 452Elm St.#3D

Burgtown OH 45201

3 TheDustmite

DustinHuff

LaserVision

452Elm St.#3D

Burgtown OH 45201

What if John Smith changes his name?

Page 18: Web Programming Week 2

2nd Normal Form

• Honor 1st Normal Form

• Create separate tables for data duplicated across rows

• Be aware of relationships!– 1:1– 1:m– m:n

Page 19: Web Programming Week 2

2NF• satisfy 1NF

• create separate tables for data duplicated across rows

id power1 Strength2 X-Ray

vision3 Flight4 Speed5 Dirtiness6 Laser

Vision

id lair_id name realname

align

1 1 CleanFreak

JohnSmith

good

2 1 SoapStud

EframJones

good

3 2 TheDustmite

DustinHuff

evil

id lairaddress

city state zip

1 123 PoplarAve

Townsburg OH 45293

2 452 ElmSt. #3D

Burgtown OH 45201

char_id power_id1 11 21 32 43 13 53 6

Are “city“ and “state“ directly related to the lairs?

Page 20: Web Programming Week 2

3rd Normal Form

• Honor 1st & 2nd Normal Form

• Create separate tables for any transitive or partial dependencies

Page 21: Web Programming Week 2

3NF• satisfy 2NF

• create separate tables for any transitive or partial dependencies

id power1 Strength2 X-Ray

vision3 Flight4 Speed5 Dirtiness6 Laser

Vision

id lair_id name realname

align

1 1 CleanFreak

JohnSmith

good

2 1 SoapStud

EframJones

good

3 2 TheDustmite

DustinHuff

evil

id zip_id lairaddress

1 45293 123 PoplarAve

2 45201 452 ElmSt. #3D

id city state45293 Townsburg OH45201 Burgtown OH

char_id power_id1 11 21 32 43 13 53 6

see note on p. 283 on why good/evil is not in a separate table

Page 22: Web Programming Week 2

That’s About as Far As We’ll Go

• Other normal forms are possible (BCNF, 4NF, 5NF)– take a database class if you’re interested

• Referential integrity– a foreign key (“link”) into another table is no

longer valid– “404 Errors” are bad in databases and should

not happen• how bad is a function of the data itself…

Page 23: Web Programming Week 2

MySQL Hierarchy

server=mln-web.cs.odu.edu

database=tennisplayers

table 1 table 2

table 3

database=superheroes

table 1 table 2

table 3

Page 24: Web Programming Week 2

Manipulating Tables & Databases

• CREATE - create new databases, tables• ALTER - modify existing tables• DELETE - erase data from tables• DESCRIBE - show structure of tables• INSERT INTO tablename VALUES - put data in

table• UPDATE - modify data in tables• DROP - destroys table or database (values +

structure)more: http://dev.mysql.com/doc/refman/5.0/en/sql-syntax.html

Page 25: Web Programming Week 2

Native MySQL Data Types

• Unlike Perl, PHP and other civilized languages, MySQL is big into data types:– http://dev.mysql.com/doc/refman/5.0/en/data-

types.html– many examples in chapter 3, 10

Page 26: Web Programming Week 2

SQL Query Form

SELECT [fieldnames]FROM [tablenames]WHERE [criteria]ORDER BY [fieldname to sort on] [DESC]LIMIT [offset, maxrows]

more: http://dev.mysql.com/doc/refman/5.0/en/select.htmllook at chapters 3 and 10 for code examples