http://api.joelburton.com/recipes/brownies?color=red
URL: "resource" : "/recipes/brownies"
REST "resource" (subject)
- "brownies" : resource recipe
- "recipes" : resource of all my recipes
HTTP methods ("verbs") -> (verb)
GET /recipes => list of my resources of recipes
combo of verb+subject resource + method
different endpoint:
GET /recipes POST /recipes (creates a resource in recipes) PUT /recipes/brownies (update brownie resource)
safe:
- doesn't change anything
- only safe method => GET
- all else => unsafe
idempotent:
- doing it multiple times same as once
- GET / PUT / PATCH / DELETE
<form method="POST">
<input name="book-title">
<button>Search</button>
</form>
=> GET /books?book-title=the+bell+jar
=> POST /books
-
"is-a" : "joel is a human", "a human is a mammal"
-
"has-a" : "an invoice has a client [eg i bill apple]"
-
"has-many" : "my company has many open invoices"
company -> invoices <- client
-
/joelco/invoices/500 { clientcode: "apple" }
-
/joelco/clients/apple {name: ..., address: ....}
entirely unrelated to browser sessions
- it just wraps a database transaction
- you have to
.commit
to keep work or.rollback
to clean fouled transactions
A way we can maintain "state" over HTTP: have browser remember & re-present
An abstraction over using cookies directly — uses them under the hood
Browser stores one (or more) cookies that hold the session data
Flask handles sending/validating authenticity of sessions
A magic dictionary because, even though the session
object
you import is global, it is magically about this browser
- breaking or reinforcing your mental model
- why and how to read error messages
- stacktrace/backtrace/traceback
- what debuggers can answer for us:
- where am and how did I get here?
- what was I called with?
- why was I called with that?
- what am I going to return?
- what are my variables?
- how would my program work differently if
x
was equal to 32? - watch code run!
Some commands I’ll show:
pip install ipdb # a prettier/nicer pdb for python
export PYTHONBREAKPOINT=ipdb.set_trace
flask run --without-threads --no-reload
Big ideas in OO:
- abstraction
- encapsulation
- polymorphism
Different areas:
- “data oo”
- “specialized subclass/machine”
- we will briefly visit this while learning how to absolutely crush your siblings in hangman