Building a Swift Web API and Application Together

Building a Swift Web API and Application Together

D200a17dd269fd4001bacb11662dab4b?s=128

Kyle Fuller

March 02, 2017
Tweet

Transcript

  1. 5.
  2. 10.
  3. 11.
  4. 35.

    WebLinking: Checking for next link if let link = response.findLink(relation:

    "next") { print("We have a next link with the URI: \(link.uri).") }
  5. 39.

    Blog Post (Next Link) { "title": "My First Blog Post",

    "body": "Lorem Ipsum", "_links": [ { "href": "/posts/2", "relation": "next" } ] }
  6. 40.

    Blog Post (Self) { "title": "My First Blog Post", "body":

    "Lorem Ipsum", "_links": [ { "href": "/posts/1", "relation": "self" }, { "href": "/posts/2", "relation": "next" } ] }
  7. 41.

    Blog Post (Comments) { "title": "My First Blog Post", "body":

    "Lorem Ipsum", "_links": [ { "href": "/posts/1", "relation": "self" }, { "href": "/posts/2", "relation": "next" }, { "href": "/posts/1/comments", "relation": "comments" }, ] }
  8. 42.

    Blog Post (Embedded Comments) { "_embed": { "comments": [ {

    "author": "Kyle", "body": "That's a really interesting post!" "_links": [ { "href": "/posts/1/comments/1", "relation": "self" } ] } ] } }
  9. 44.

    Delete Post { "properties": { "title": "My First Blog Post",

    "body": "Lorem Ipsum", }, "actions": [ { "name": "delete", "method": "DELETE", "href": "/posts/1" } ] }
  10. 45.

    Delete Post { "properties": { "title": "My First Blog Post",

    "body": "Lorem Ipsum", }, "actions": [ { "name": "delete", "method": "DELETE", "href": "/posts/1" } ] }
  11. 46.

    Create Comment { "properties": { "title": "My First Blog Post",

    "body": "Lorem Ipsum", }, "actions": [ { "name": "comment", "method": "POST", "href": "/posts/1/comments", "fields": [ { "name": "author", "type": "string" }, { "name": "message", "type": "string" } ] } ] }
  12. 47.

    Create Comment (Logged in) { "properties": { "title": "My First

    Blog Post", "body": "Lorem Ipsum", }, "actions": [ { "name": "comment", "method": "POST", "href": "/posts/1/comments", "fields": [ { "name": "message", "type": "string" } ] } ] }
  13. 57.
  14. 58.

    XCTest class PersonTests: XCTestCase { let person = Person(name: "Kyle")

    func testPersonName() { XCTAssertEqual(person.name, "Kyle") } func testPersonDescription() { XCTAssertEqual(person.description, "Kyle") } }
  15. 59.

    extension PersonTests: XCTestCaseProvider { var allTests : [(String, () throws

    -> Void)] { return [ ("testPersonName", testPersonName), ("testPersonDescription", testPersonDescription), ] } } XCTMain([ PersonTests(), ])
  16. 65.

    $ cat Package.swift import PackageDescription let package = Package( name:

    "Hello", dependencies: [ .Package(url: "https://github.com/nestproject/Frank.git", majorVersion: 0, minor: 3), ] )
  17. 66.

    $ cat Sources/main.swift import Frank get { _ in return

    "Hello World" } get(*) { (_, username: String) in return "Hello \(username)" }
  18. 67.

    $ cat Sources/main.swift import Frank get { _ in return

    "Hello World" } get(*) { (_, username: String) in return "Hello \(username)" }
  19. 72.

    $ heroku create --buildpack https://github.com/kylef/heroku-buildpack-swift.git $ git push heroku master

    remote: -----> Swift app detected remote: -----> Installing 3.0.2 remote: -----> Installing clang-3.7.0 remote: -----> Building Package remote: -----> Copying binaries to 'bin'
  20. 73.
  21. 74.
  22. 75.
  23. 78.
  24. 81.
  25. 82.