Kitura Logo

GETTING STARTED

Before Starting

Check you have all required prerequisites installed.

Once you have installed them, you can choose between Option 1 which uses a macOS application to generate a project, or Option 2 which uses a command line tool.

Option 1: Kitura macOS App

App Screengrab

Get started without the command line by using our new macOS app. It will download dependencies using a template and opens the project automatically.

Once you have downloaded and installed the app using the above link, run it and select the Starter tile, and name your project HelloKitura in the dialog box. Once it has created the project, select Open. This will open the project in Xcode.

You're now ready to skip ahead to Creating Your App.

Option 2: Kitura Command Line Interface (CLI)

The Kitura CLI offers a quick way get started on both macOS and supported Linux platforms using the Terminal. See the source for it on GitHub.

Install Homebrew:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Install Homebrew tap.

Installing Kitura’s Homebrew tap will allow brew to access Kitura’s package repository.

brew tap ibm-swift/kitura

Install Kitura’s command-line interface.

brew install kitura

Create a directory for your Kitura project.

mkdir HelloKitura
cd HelloKitura

Using the Kitura command-line interface, generate a basic starter project.

kitura init

You can learn more about the project generation here.

Open the generated HelloKitura.xcodeproj project in Xcode.

open HelloKitura.xcodeproj

Creating Your App

Edit Sources/Application/Application.swift and add the following code inside the postInit() function.

// Handle HTTP GET requests to "/"
router.get("/") { request, response, next in
    response.send("Hello, World!")
    next()
}

Edit the Xcode build scheme so it specifies HelloKitura as the Executable (by default it will be set to HelloKitura-Package when you open Xcode).

EditXcodeBuildSchema

Click the play button (⌘-R) to build and run your new web application.

Open your web browser at http://localhost:8080.

You should see the following page in your browser:

"Hello, World!"

Congratulations! You have just created your first server-side Swift application using Kitura.

Learn how to build a back-end for the TodoList web application.

Learn how to build a back-end for the Apple FoodTracker iOS application.

Slack icon

NEED HELP?

MESSAGE US ON SLACK.