Building a Vapor application from scratch
Before we start creating Vapor applications using the Vapor toolbox, which is an awesome tool provided by the Vapor team, let's see the minimal amount of code needed to create a Vapor application from scratch using the Vapor package. To do so, we need to follow the following steps:
- Create a new
Hello
folder and open it in the Terminal. - Then, initialize the Swift package by running the
init
command, and make it an executable type. This should generate theSources
folder andTest
folder, and also create aPackage.swift
file:
$ swift package init --type executable
- Update the dependencies section in
Package.swift
to include Vapor as a dependency, and also include Vapor in the target dependency for theHello
target:
let package = Package( name: "Hello", dependencies: [ .package(url: "https://github.com/vapor/vapor.git", .upToNextMajor(from: "2.4.4")), ], targets: [ .target( name: "Hello", dependencies: ["Vapor"]), ] )
- Now, we need...