1. How does the web work?
aka HTTP 101
by Guilherme Cavalcanti
@guiocavalcanti
2. Schedule
1. Some Web Principles
2. REST
3. HTTP
Verbs
Idempotency
Side effects
GET and POST Vs. PUT and DELETE
4. Rails
5. AJAX vs. Accessibility
3. Some Web Principles
Universality
Any resource anywhere can be given a URI
Any resource of significance should be given a URI.
Resources are documents
As well as concepts and abstract ideias (Semantic Web)
Global Scope
It doesn't matter to whom or where you specify that URI, it will
have the same meaning.
4. REST
Architectural style coined by Roy Fielding (phd dissertation)5
State transference
At any particular time, a client can either be in transition
between application states or "at rest". A client in a rest state
is able to interact with its user, but creates no load and
consumes no per-client storage on the servers or on the
network4
The HTTP portocols uses the rest style
5. HTTP Verbs
Side effect
change or not the state of the world
Idempotency
the side-effects of N > 0 identical requests is the same as for a
single request
6. HTTP Verbs
Idempotent Cacheable Side effects
GET
x x
POST
x
PUT
x x
DELETE
x
7. HTTP: RESTful services vs lack of verbs
PUT
Put ssomething at some place
Updates something
PUT http://redu.com.br/spaces/my-space
Content: My new Space
POST
The server decides which action gonna be taken
POST http://redu.com.br/spaces/filter
Content: name=my;audience=[higher-edu,sat]
DELETE
Deletes some resource
DELETE http://redu.com.br/spaces/my-space
8. HTTP: RESTful services vs lack of verbs
Doesn't work on6
< HTML 4
< XHTML 1.0
It works on
XMLHttpRequests (aka AJAX)3
9. HTTP: RESTful services vs lack of verbs
POST acting as PUT
POST http://redu.com.br/spaces
Content: name=My Space;path=my-space
POST acting as PUT when updating
POST http://redu.com.br/spaces/my-space
Content: _method=PUT
POST acting as DELETE
POST http://redu.com.br/spaces/my-space
Content: _method=DELETE