Bittiger cs101 notebook 6 - web programming
Contents
Http and Chrome dev tools
Http header
- Host: send to where, dns lookup
- Referer: linked from where,
- User-Agent: browser, os
- Cache-Control:
- static: can cache
- non-static: cannot cache
- static: can cache
- Date: timestamp
Http request methods
GET
HEAD
POST: post data
PUT: store data
DELETE
TRACE
OPTIONS
CONNECT
status
304: cached content
Restful api
reasons:
- single page application
- mobile and other services
Representational State Transfer
Resources
Representational
Accept: xml json etc
State Transfer
Stateless
- No client state at server
- Any State is maintained at Client side
- Each request has all the information to process the request: the same url/request will get the same response
Restful api: Good examples:
- A URL indentifies a resource
- URLs should include nouns, not verbs
good: Post https://url
bad: https://url/post - Use http verbs(GET, POST, DELETE, PUT)
| POST | GET | PUT | DELETE | |-|-|-|-| | CREATE | READ | UPDATE | DELETE | - Use plural noun only for consistency, not single
- don’t need to go deeper than resource/identifier/resource
- put version number at your api
- specify optional fields in a comma seperated list
- example: need to tradeoff
not rest: POST www.url.com/login
restful: GET www.url.com/users/{username}
Author Chen Tong
LastMod 0001-01-01