INF397 Full Stack Technologies View Schedule Print

RESTful principles

REST stands for REpresentational State Transfer.

Originally a PHD thesis descibing a set of architectural principles for building scalable and maintainable web systems.

Rules

  • The system is organized as resources with capabilites
  • The system is connected through hyper-media
  • Stateless Communication
  • Uniform Interfaces

Resources and Representations

URI stand for Uniform Resource Indentifier

  • Resources must have unique identities
  • Resources expose sets of capabilities
  • Resources can have multiple representations
  • Resources must difine a caching policy
  • Capabilities should be accessible through uniform interfaces

Hyper-media

Links provide access to resources & capabilites
  • Links are the application entry points
  • Links decouple communication
  • Links are platform independant

Actions and Side effects

Side effects are indirect consequences
e.g. unexpected state-mutation, event triggering
  • Actions should be predictable
  • Side effects should be made explict

HTTP Verbs

  • GET: retrieve resources, should not change data
  • POST: create resources
  • PUT: change/update resources
  • DELETE: remove resources
  • HEAD: read resources headers
DOes:
  • Use well known formats and protocols
  • Do not keep session state on the server between requests
  • Return links to further actions and resources
  • Use templates and forms to help clients build complex requests
DONTs:
  • Thinking only about pretty looking templated URLs
  • Constructing URLs manually
  • Hardcoding URLs

To-do representation example


  {
    "id": "id123",
    "message": "get milk",
    "done": false,
    "methods": {
      "get": {  "url": "todo.xyz/task/id123", "method": "GET" },
      "toggle": { "url": "todo.xyz/task/id123/toggle", "method": "PUT" },
      "edit": { "url": "todo.xyz/task/id123/message", "method": "PUT" },
      "delete": { "url": "todo.abc/task/id123", "method": "DELETE" }
    }
  }
  

    <article сlass="todo-task" id="id123">
      <form сlass="toggle"
        action="todo.xyz/task/id123/toggle" method="PUT">
        <input type="checkbox" checked/>
        <input type="submit" value="toggle"/>
      </form>
      <p class="message">get milk</p>
      <a href="todo.xyz/task/id123">View item</a>
      <form class="delete" action="todo.abc/task/id123"
        method="DELETE">
        <input type="submit" value="delete"/>
      </form>
    </article>
  

To-do representation example

Notice the shape of the example object. Creating a task returns a representation with all methods, not just an id.
This means you can add functionality without changing the frontend.
Do the urls need to be human readable? No, but's its a plus if they are easy to understand.

Web Hooks

A way for services to communicate asynchronous
  1. A client service sends our service a callback url
  2. Our service stores the callback urls per event type
  3. Our service sends data to all callback urls when a specific event happens within our sevice
  4. The client service processes the event data

Course Schedule:

week 1 03.02.2017 History of the web Fullstack Principles Development Processes Agile Processes DevOps Basics Git
week 2 10.02.2017 Frontend Overview Backend Overview Network Overview Testing JavaScript Overview JavaScript Tooling
week 3 17.02.2017 Web Architectures RESTful principles SOLID principles Web Components Continuous Integration
week 4 24.02.2017 Databases basics Using APIs Deployment Automation Monitoring In-class project consultations
week 5 17.03.2017 Project presentations
Final Test
Course Retrospective and Q&A