Skip to content

Getting Started

Elliott Minns edited this page Mar 5, 2016 · 9 revisions

Getting Started

You must have Swift 2.2 or later installed. You can learn more about Swift 2.2 at Swift.org

Blackfish is tested using the latest Swift Development snapshots, with current testing using snapshot March 1st, 2016

You also need to have libuv installed.

You can install this using either homebrew on OS X or apt-get on Ubuntu

OS X

$ brew install libuv

Ubuntu

$ sudo apt-get install automake libtool
$ curl -O http://dist.libuv.org/dist/v1.8.0/libuv-v1.8.0.tar.gz
$ tar xzf libuv-v1.8.0.tar.gz
$ cd libuv-v1.8.0 && sh autogen.sh
$ ./configure                                                       
$ make && sudo make install

To build a Blackfish app, you must call swift build and add your libuv linker path

$ swift build -Xlinker -L/usr/local/lib

See the Blackfish Example for more details, and how to create a makefile

## Setting up the project.

Starting the app is a simple process.

Package.swift

dependencies: [
    // Other dependencies
    .Package(url: "https://github.com/elliottminns/blackfish.git", majorVersion: 0)
]

Then, in your main.swift file create an instance of Blackfish

main.swift

import Blackfish

let app = BlackfishApp()

// Add routes
app.get("/") { request, response in
    response.send(text: "Hello World!")
}

app.listen(port: 3000) { error in
    if error == nil {
        print("Example app listening on port 3000")
    }
}

If you are having trouble connecting, make sure your ports are open. Check out apt-get ufw for simple port management.

## Hello World

First create a directory named MyApp, change to it, create a file called Package.swift and add the following code.

import PackageDescription

let package = Package(name: "MyApp",
    dependencies: [
        .Package(url: "https://github.com/elliottminns/blackfish.git", majorVersion: 0)
    ]
)

In the myapp directory, create a directory named Sources, add a file inside called main.swift and add the following code:

import Blackfish

let app = BlackfishApp()

app.get("/") { request, response in
    response.send(text: "Hello world")
}

app.listen(port: 3000) { error in 
    print(error ?? "App listening on port \(app.port)"
}

Run the app with the following command To build a Blackfish app, you must call swift build and add your libuv linker path

$ swift build -Xlinker -L/usr/local/lib && .build/debug/MyApp

Then, load http://localhost:3000/ in a browser to see the output.

Roadmap

Guide

Clone this wiki locally