Use third-party framework vapor and swift to build local servers

Source: Internet
Author: User

See a tutorial on the internet, using vapor to build the service side, to record their own memo this article mainly records the following points

1. Configure the Vapor

2. Using Swift to write the Get,post method, return the JSON data

3. Configure the local server, compile and run the browser access http://localhost:8080 view return data

4. Deploy your own cloud server on Heroku, Access https://limice.herokuapp.com to view return data

I. Installation vapor, recommended view official tutorial address: https://vapor.github.io/documentation/getting-started/install-swift-3-macos.html

First, make sure you've installed Xcode8.

Run the following command on the terminal

$ CURL-SL check.vapor.sh | Bash

$ CURL-SL toolbox.vapor.sh | Bash

$ Vapor--help

New Project

$ Vapor New Hellovapor

Want to open this project in Xcode and compile the run, CD into the project file first, then run

$ Vapor xcode-y

This is a slow step, just a few more.

Open Xcode in Code view sources/app/main.swift code in remove

Import Vapor

Let drop = Droplet ()

Drop.run ()

All code outside of

Two. Add the Get and POST request codes before drop.run this line

Three. you can view the returned JSON data by accessing http://localhost:8080 or 0.0.0:8000

Four. Heroku (http://www.heroku.com/) is a mobile phone cloud platform, first register an account and then install the deployment environment, first download the installer (address: https://s3.amazonaws.com/assets.heroku.com/ HEROKU-TOOLBELT/HEROKU-TOOLBELT.PKG)

Whether the terminal check is successful

Localhost:hellovapor admin$ Heroku--version
heroku-toolbelt/3.43.11 (x86_64-darwin10.8.0) ruby/1.9.3
HEROKU-CLI/5.4.8-EEE5EC9 (DARWIN-AMD64) go1.7.1
You have no installed plugins.
Localhost:hellovapor admin$

Next is the terminal login Heroku, run

$ Heroku Login

You can enter your account password

To run the CD into the project folder

$ git init

$ git Add.

$ git commit-am "first Swift server"

and deploy our servers.

$ Vapor Heroku Init

After successful run a try, my domain name is https://limice.herokuapp.com/run your custom JSON data Hello,vapor

Heroku modifying local file Submissions

commit -m ‘say somethig‘git push heroku master

Original Blog Address: http://www.jianshu.com/p/3fc28570d951

Use third-party framework vapor and swift to build local servers

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.