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

Vaporで始めるServer side Swift

Vaporで始めるServer side Swift

Asakura Shinsuke

May 02, 2018
Tweet

More Decks by Asakura Shinsuke

Other Decks in Technology

Transcript

  1. Options 3 Name Flag Description API --template=api JSON API with

    Fluent database. Web --template=web clones http://github.com/vapor/web- template --template=user/repo clones http://github.com/user/repo. --template=http://hogehgoe.com/ repo clones the full url given. --branch=foo can be used to specify a branch besides master. 3 https://docs.vapor.codes/2.0/getting-started/toolbox/#templates
  2. Build & Run $ vapor build $ vapor run //

    or Run(⌘ + R) on Xcode
  3. Model final class UserModel: Model { let storage = Storage()

    struct Keys { static let id = "id" static let name = "name" static let age = "age" } static let idType: IdentifierType = .uuid var name: String var age: Int = 0 init(name: String, age: Int ) { self.name = name self.age = age } required init(row: Row) throws { name = try row.get(UserModel.Keys.name) age = try row.get(UserModel.Keys.age) } func makeRow() throws -> Row { var row = Row() try row.set(UserModel.Keys.name, name) try row.set(UserModel.Keys.age, age) return row } }
  4. Controller final class UserController: ResourceRepresentable { func makeResource() -> Resource<UserModel>

    { return Resource( index: index, store: store, show: show, update: update, replace: replace, destroy: delete, clear: clear ) } }