mirror of https://github.com/vapor/docs.git
This commit is contained in:
commit
80f3ecd4a9
|
|
@ -0,0 +1 @@
|
|||
/.couscous
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
template:
|
||||
url: https://github.com/CouscousPHP/Template-Dark
|
||||
|
||||
title: Vapor Documentation
|
||||
subTitle: A web framework and server for Swift that works on macOS and Ubuntu.
|
||||
|
||||
menu:
|
||||
sections:
|
||||
links:
|
||||
name: Links
|
||||
items:
|
||||
website:
|
||||
text: Qutheory.io
|
||||
absoluteUrl: http://qutheory.io
|
||||
example:
|
||||
text: Example
|
||||
absoluteUrl: http://example.qutheory.io
|
||||
github:
|
||||
text: GitHub
|
||||
absoluteUrl: https://github.com/qutheory/vapor
|
||||
twitter:
|
||||
text: Twitter
|
||||
absoluteUrl: https://twitter.com/@qutheory
|
||||
slack:
|
||||
text: Slack
|
||||
absoluteUrl: http://slack.qutheory.io
|
||||
getting-started:
|
||||
name: Getting Started
|
||||
items:
|
||||
getting-started-install-swift-3-macos:
|
||||
text: Install Swift 3: macOS
|
||||
relativeUrl: getting-started/install-swift-3-macos.html
|
||||
getting-started-install-swift-3-ubuntu:
|
||||
text: Install Swift 3: Ubuntu
|
||||
relativeUrl: getting-started/install-swift-3-ubuntu.html
|
||||
getting-started-install-swift-3:
|
||||
text: Install Swift 3
|
||||
relativeUrl: getting-started/install-swift-3.html
|
||||
getting-started-install-toolbox:
|
||||
text: Install Toolbox
|
||||
relativeUrl: getting-started/install-toolbox.html
|
||||
getting-started-hello-world:
|
||||
text: Hello, World
|
||||
relativeUrl: getting-started/hello-world.html
|
||||
guide:
|
||||
name: Guide
|
||||
items:
|
||||
guide-routing:
|
||||
text: Routing
|
||||
relativeUrl: guide/routing.html
|
||||
|
|
@ -0,0 +1,112 @@
|
|||
---
|
||||
currentMenu: getting-started-hello-world
|
||||
---
|
||||
|
||||
# Hello, World
|
||||
|
||||
This section assumes you have installed Swift 3 and the Vapor Toolbox and have verified they are working.
|
||||
|
||||
## New Project
|
||||
|
||||
Let's start by creating a new project called Hello, World
|
||||
|
||||
```sh
|
||||
vapor new Hello
|
||||
```
|
||||
|
||||
Vapor's folder structure will probably look familiar to you if you have worked with other web frameworks.
|
||||
|
||||
```
|
||||
.
|
||||
├── App
|
||||
│ └── Controllers
|
||||
│ └── Middleware
|
||||
│ └── Models
|
||||
│ └── main.swift
|
||||
├── Public
|
||||
├── Resources
|
||||
│ └── Views
|
||||
└── Package.swift
|
||||
```
|
||||
|
||||
For our Hello, World project, we will be focusing on the `main.swift` file.
|
||||
|
||||
```
|
||||
.
|
||||
└── App
|
||||
└── main.swift
|
||||
```
|
||||
|
||||
Note: The `vapor new` command creates a new project with examples and comments about how to use the framework. You can delete these if you want.
|
||||
|
||||
## Droplet
|
||||
|
||||
Look for the following line in the `main.swift` file.
|
||||
|
||||
```swift
|
||||
let drop = Droplet()
|
||||
```
|
||||
|
||||
This is where the one and only `Droplet `for this example will be created. The `Droplet` class has a plethora of useful functions on it, and is used extensively.
|
||||
|
||||
## Routing
|
||||
|
||||
Right after the creation of `drop`, add the following code snippet.
|
||||
|
||||
```swift
|
||||
drop.get("hello") { request in
|
||||
return "Hello, world!"
|
||||
}
|
||||
```
|
||||
|
||||
This creates a new route on the `Droplet` that will match all `GET` requests to `/hello`.
|
||||
|
||||
All route closures are passed an instance of [Request](/guide/request.html) that contains information such as the URI requested and data sent.
|
||||
|
||||
This route simply returns a string, but anything that is [ResponseRepresentable](/guide/routing.html) can be returned. Learn more in the [Routing](/guide/routing.html) section of the guide.
|
||||
|
||||
## Serving
|
||||
|
||||
At the bottom of the main file, make sure to serve your `Droplet`.
|
||||
|
||||
```swift
|
||||
drop.serve()
|
||||
```
|
||||
|
||||
Save the file, and switch back to the terminal.
|
||||
|
||||
## Compiling
|
||||
|
||||
A big part of what makes Vapor so great is Swift's state of the art compiler. Let's fire it up. Make sure you are in the root directory of the project and run the following command.
|
||||
|
||||
```swift
|
||||
vapor build
|
||||
```
|
||||
|
||||
Note: `vapor build` runs `swift build` in the background.
|
||||
|
||||
The Swift Package Manager will first start by downloading the appropriate dependencies from git. It will then compile and link these dependencies together.
|
||||
|
||||
When the process has completed, you will see `Building Project [Done]`
|
||||
|
||||
Note: If you see a message like `unable to execute command: Killed`, you need to increase your swap space. This can happen if you are running on a machine with limited memory.
|
||||
|
||||
## Run
|
||||
|
||||
Boot up the server by running the following command.
|
||||
|
||||
```swift
|
||||
vapor run serve
|
||||
```
|
||||
|
||||
You should see a message `Server starting...`. You can now visit `http://localhost:8080/hello` in your browser.
|
||||
|
||||
Note: Certain port numbers require super user access to bind. Simply run `sudo vapor run` to allow access. If you decide to run on a port besides `80`, make sure to direct your browser accordingly.
|
||||
|
||||
## Hello, World
|
||||
|
||||
You should see the following output in your browser window.
|
||||
|
||||
```
|
||||
Hello, world!
|
||||
```
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
---
|
||||
currentMenu: getting-started-install-swift-3-macos
|
||||
---
|
||||
|
||||
# Install Swift 3: macOS
|
||||
|
||||
To use Vapor on macOS, you need to have Xcode 8 installed and selected.
|
||||
|
||||
## Download
|
||||
|
||||
To download Xcode 8, visit [Apple Developer Downloads](https://developer.apple.com/download/) or [Swift.org Downloads](https://swift.org/download/#using-downloads)
|
||||
|
||||
## Install
|
||||
|
||||
After Xcode 8 has downloaded, drag it into your Applications folder and open it. It may take a while to verify the download.
|
||||
|
||||
## Select
|
||||
|
||||
Select Xcode 8 for your Command Line Tools.
|
||||
|
||||
- Open Xcode 8 and go to Preferences (`cmd`+`,`)
|
||||
- Select the Locations tab
|
||||
- Under Command Line Tools choose `Xcode 8.0 (xxxxx)`
|
||||
|
||||
## Swift
|
||||
|
||||
You can now move on to [Install Swift 3](/getting-started/install-swift-3.html)
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
---
|
||||
currentMenu: getting-started-install-swift-3-ubuntu
|
||||
---
|
||||
|
||||
# Install Swift 3: Ubuntu
|
||||
|
||||
To use Swift 3 on Ubuntu, you need to have its dependencies installed.
|
||||
|
||||
## Install
|
||||
|
||||
Depending on your flavor of Ubuntu, you may need some additional tools for the compiler. We'll err on the safe side and install everything you should need
|
||||
|
||||
```sh
|
||||
sudo apt-get update
|
||||
sudo apt-get install clang libicu-dev binutils git
|
||||
```
|
||||
|
||||
## Swift
|
||||
|
||||
You can now move on to [Install Swift 3](/getting-started/install-swift-3.html)
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
---
|
||||
currentMenu: getting-started-install-swift-3
|
||||
---
|
||||
|
||||
# Install Swift 3
|
||||
|
||||
This section assumes you have followed the operating system specific instructions for either macOS or Ubuntu.
|
||||
|
||||
To use Vapor, you must have Swift 3 installed. Each version of Vapor relies on a single Development Snapshot of Swift 3. Vapor 0.15 relies on `DEVELOPMENT-SNAPSHOT-2016-07-25-a`.
|
||||
|
||||
## Swiftenv
|
||||
|
||||
[Swiftenv](https://github.com/kylef/swiftenv) allows you to easily install, and switch between multiple versions of Swift.
|
||||
|
||||
### Install
|
||||
|
||||
Clone the program to your home directory.
|
||||
|
||||
```sh
|
||||
git clone https://github.com/kylef/swiftenv.git ~/.swiftenv
|
||||
```
|
||||
|
||||
Initialize Swiftenv in your Bash profile.
|
||||
|
||||
```sh
|
||||
export SWIFTENV_ROOT="$HOME/.swiftenv"
|
||||
export PATH="$SWIFTENV_ROOT/bin:$PATH"
|
||||
eval "$(swiftenv init -)"
|
||||
```
|
||||
|
||||
Note: macOS uses `~/.bash_profile` and Ubuntu uses `~/.bashrc`
|
||||
|
||||
### Verify
|
||||
|
||||
Open a new terminal window and run `swiftenv --version`. You should see something like the following.
|
||||
|
||||
```sh
|
||||
$ swiftenv --version
|
||||
swiftenv 1.1.0
|
||||
```
|
||||
|
||||
## Download Snapshot
|
||||
|
||||
Now that Swiftenv has been installed, the development snapshot of Swift 3 can be downloaded.
|
||||
|
||||
```sh
|
||||
swiftenv install DEVELOPMENT-SNAPSHOT-2016-07-25-a
|
||||
```
|
||||
|
||||
This will download and install the snapshot. You can then make that snapshot globally available as `swift`.
|
||||
|
||||
```sh
|
||||
swiftenv global DEVELOPMENT-SNAPSHOT-2016-07-25-a
|
||||
```
|
||||
|
||||
### Verify
|
||||
|
||||
Run `swiftenv versions` to list the versions of Swift 3 installed.
|
||||
|
||||
```sh
|
||||
$ swiftenv versions
|
||||
* DEVELOPMENT-SNAPSHOT-2016-07-25-a (set by /Users/vapor/.swiftenv/version)
|
||||
```
|
||||
|
||||
## Check
|
||||
|
||||
To ensure that your environment has been correctly configured, run the check script.
|
||||
|
||||
```sh
|
||||
curl -sL check.qutheory.io | bash
|
||||
```
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
---
|
||||
currentMenu: getting-started-install-toolbox
|
||||
---
|
||||
|
||||
# Install Toolbox
|
||||
|
||||
Vapor's command line interface provides shortcuts and assistance for commons tasks.
|
||||
|
||||
## Install
|
||||
|
||||
Run the following script to install the [Toolbox](https://github.com/qutheory/toolbox).
|
||||
|
||||
```sh
|
||||
curl -sL toolbox.qutheory.io | bash
|
||||
```
|
||||
|
||||
Note: You must have the correct version of Swift 3 installed.
|
||||
|
||||
## Verify
|
||||
|
||||
Make sure the Toolbox installed successfully by running the help query. You should see a print out of the available commands. You can run the `--help` option on any Toolbox command.
|
||||
|
||||
```sh
|
||||
vapor --help
|
||||
```
|
||||
|
||||
## Updating
|
||||
|
||||
The toolbox can update itself. This may be useful if you experience any issues in the future.
|
||||
|
||||
```sh
|
||||
vapor self update
|
||||
```
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
currentMenu: guide-routing
|
||||
---
|
||||
|
||||
# Routing
|
||||
|
||||
This is how routing works.
|
||||
|
||||
```swift
|
||||
let drop = Droplet()
|
||||
```
|
||||
Loading…
Reference in New Issue