Upgrade to Pro — share decks privately, control downloads, hide ads and more …

REST framework: Under the Hood

C498214bc28f28b61212169dcc372fbf?s=47 Tom Christie
November 15, 2014

REST framework: Under the Hood

C498214bc28f28b61212169dcc372fbf?s=128

Tom Christie

November 15, 2014
Tweet

Transcript

  1. REST framework: Under the Hood. Saturday, 15 November 14

  2. Serialization. Saturday, 15 November 14

  3. ↕ ↑ ↓ Serialization Rendering Parsing Saturday, 15 November 14

  4. Saturday, 15 November 14

  5. Saturday, 15 November 14

  6. Saturday, 15 November 14

  7. Saturday, 15 November 14

  8. Problem: Related data. Saturday, 15 November 14

  9. Saturday, 15 November 14

  10. Saturday, 15 November 14

  11. Saturday, 15 November 14

  12. Problem: Encapsulation. Saturday, 15 November 14

  13. “Fat models, thin views.” ↓ “Never write to a model

    field or call .save() directly. Always use model methods and manager methods for state changing operations.” Saturday, 15 November 14
  14. Saturday, 15 November 14

  15. Saturday, 15 November 14

  16. Problem: Hidden validation behavior. Saturday, 15 November 14

  17. Saturday, 15 November 14

  18. Saturday, 15 November 14

  19. Saturday, 15 November 14

  20. We want explicit validation behavior, but we’d still like the

    ModelSerializer shortcut. Saturday, 15 November 14
  21. Saturday, 15 November 14

  22. Saturday, 15 November 14

  23. We can use the ModelSerializer shortcut, but our validation behavior

    is made visible & explicit. • unique_together • field validation Saturday, 15 November 14
  24. Consequences of dropping ‘Model.full_clean()’ • All field validation handled. •

    All uniqueness validation handled. • `Model.clean()` → `Serializer.validate()` Saturday, 15 November 14
  25. BaseSerializer. Saturday, 15 November 14

  26. Saturday, 15 November 14

  27. Saturday, 15 November 14

  28. Saturday, 15 November 14

  29. Rendering. Saturday, 15 November 14

  30. Saturday, 15 November 14

  31. Saturday, 15 November 14

  32. Accessing field information... Saturday, 15 November 14

  33. Saturday, 15 November 14

  34. Saturday, 15 November 14

  35. Saturday, 15 November 14

  36. Simulating nested and list structures in HTML... Saturday, 15 November

    14
  37. Saturday, 15 November 14

  38. Avoid coupling fields to HTML too tightly... Saturday, 15 November

    14
  39. Saturday, 15 November 14

  40. Saturday, 15 November 14

  41. Once we’ve got all that it’s easy enough to write

    a renderer class that uses templated HTML generation... Saturday, 15 November 14
  42. Saturday, 15 November 14

  43. Saturday, 15 November 14

  44. The REST framework 3.0 big picture. • Easier to override

    save behavior. • More explicit validation. • Better model encapsulation. • Less complex internal implementation. • Supports both Form and API output. • Template based form rendering. • Nested forms and lists of forms. • API compatibility with CBVs. • BaseSerializer for custom cases. Saturday, 15 November 14
  45. Web APIs: The Next Level. Saturday, 15 November 14

  46. Hypermedia formats • HAL, JSON-LD, SIREN, UBER. • Not yet

    compelling. Saturday, 15 November 14
  47. RSS • Machine readable hypermedia format. • Big win due

    to shared tooling. • Domain specific. Saturday, 15 November 14
  48. HTML • Closest we’ve come to a universal platform. •

    Document centric, not data centric. • Not intended for programmatic interaction. Saturday, 15 November 14
  49. Layering in Web Applications. Saturday, 15 November 14

  50. Saturday, 15 November 14

  51. Saturday, 15 November 14

  52. Saturday, 15 November 14

  53. Saturday, 15 November 14

  54. Document Object Model Data Object Model • An abstract object

    interface. • Agnostic to UI environment. • Programmable. • Implied UI model. • Browser environment only. • Not programmable. ~ Saturday, 15 November 14
  55. Saturday, 15 November 14

  56. Saturday, 15 November 14

  57. Saturday, 15 November 14

  58. Generic client libraries. Saturday, 15 November 14

  59. Saturday, 15 November 14

  60. Saturday, 15 November 14

  61. Saturday, 15 November 14

  62. Saturday, 15 November 14

  63. Saturday, 15 November 14

  64. Application interfaces. Saturday, 15 November 14

  65. Saturday, 15 November 14

  66. • Generic client libraries. • In-browser tools. • Functional testing

    of our applications. • UI binding libraries. • Transparently upgrade encoding or transport layers. The big wins. Saturday, 15 November 14
  67. It’s time to start addressing the fundamental issues of system

    communication. ~ How do we design abstract object interfaces, and describe the actions and transforms they expose. Saturday, 15 November 14
  68. Thank you. @_tomchristie Saturday, 15 November 14