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

Embracing Change - MBLTDev 2015

Kyle Fuller
November 17, 2015

Embracing Change - MBLTDev 2015

Building applications can quickly become frustrating when you need to adapt to business changes. You'll often need to re-write portions of your application. Learn how you can avoid deploying updates to your application by decoupling your application from the web API. Transform your app to be simpler and more robust by keeping business logic where it belongs, on the server.

Kyle Fuller

November 17, 2015
Tweet

More Decks by Kyle Fuller

Other Decks in Technology

Transcript

  1. HAL $ curl https://polls.apiblueprint.org/ -H 'Accept: application/hal+json' { "_links": {

    "questions": { "href": "/questions" }, "self": { "href": "/" } } }
  2. HAL $ curl https://polls.apiblueprint.org/questions/1 -H 'Accept: application/hal+json' { "question": "Favourite

    programming language?", "_links": {"self": {"href": "/questions/1"}}, "_embed": { "choices": [ { "_links": {"self": {"href": "/questions/1/choices/1"}}, "choice": "Swift", "votes": 483 } ] } }
  3. $ curl https://polls.apiblueprint.org/questions -H 'Accept: application/hal+json' { "_links": { "first":

    {"href": "/questions"}, "self": {"href": "/questions"}, "next": {"href": "/questions?page=2"} "last": {"href": "/questions?page=2"}, }, }
  4. SIREN { "actions": [ { "name": "create", "method": "POST", "type":

    "application/json", "href": "/questions", "fields": [ { "name": "question", "type": "text", "title": "Question" }, { "name": "choices", "type": "array[text]", "title": "Choices" } ] } ] }
  5. API BLUEPRINT ## Questions Collection [/questions] ### Create a new

    question [POST] + Relation: create + Request (application/json) + Attributes + question (string, required) + choices (array[string], required) + Response 201 (application/json) + Attributes (Question)
  6. hyperdrive.enter("http://localhost:8000/") // follow the 'questions' transition .flatMap { hyperdrive.request($0.transitions["questions"]) }

    // Follow the 'create' transition .flatMap { hyperdrive.request($0.transitions["create"], attributes: [ "question": "types of egg", "choices": ["hard boiled eggs", "soft boiled eggs"] ]) } // Select the first choice .map { $0.representors["choices"]!.first! } // Follow the 'vote' transition .flatMap { hyperdrive.request($0.transitions["vote"]) }
  7. /// Returns whether the user may create a question var

    canCreateQuestion: Bool { return representor.transitions["create"] != nil }
  8. /// Returns whether the user may delete the question at

    the given index func canDeleteQuestion(index: Int) -> Bool { let transition = questions?[index].transitions["delete"] return transition != nil }
  9. import JSONSchema let schema = Schema([ "type": "object", "properties": [

    "question": ["type": "string"], "choices": ["type": "array", "minItems": 2], ], ]) schema.validate([ "question": "Favourite Conference?", "choices": [ "MBLTDev 2015" ] ])