Sample application for Kitura Web Framework
This Kitura sample shows off the powerful features available in Kitura 2, baking several demos into one project. You can access the individual examples by navigating to their specific routes in a browser.
It features the following:
- Kitura WebSocket based chat server
- Stencil template engine example
- Using multiple handlers per route
- Reading and accepting parameters in a route
Getting Set Up
Install the prerequisites (ignore the requirement to install Homebrew on macOS as it is not required for this sample).
git clone https://github.com/IBM-Swift/Kitura-Sample.git && cd Kitura-Sample
Note: do not use the GitHub "Download ZIP" button
You should see a message Listening on port 8080. You may need to click "Allow" if a security pop up appears, dependent on your firewall settings.
Open your browser at http://localhost:8080.
Navigate to one of the example routes on the localhost URL, for example, for the chat server go to localhost:8080/chat.
This demo sets up a local chat server using Kitura's WebSocket library, and the UI mimicks a chat room. Two separate browser windows pointed to the
/chat route can be used to represent two people in the chat room if the project is running on localhost. It can also be deployed to the IBM Cloud and then accessed via a Cloud Foundry App.
Stencil Templating Engine
Kitura supports the popular Stencil Templating Engine, using the Kitura Stencil library. This route looks for a Stencil file in a subdirectory called
Views and renders the page with it.
Multiple Handlers in one Route
Kitura supports multiple handlers per route, this example prints several lines to the window using different
Reading and Accepting Parameters
Note: This example uses
:users but you can use anything you like, as long as the first part of the route is
This route accepts a parameter in its URL and uses that parameter in its HTML creation. It does this using a colon (:) in the URL which defines the item following it as a parameter. It then assigns this parameter to a variable, and concatenates it into the HTML.
To run the tests locally, run
swift test from the Kitura-Sample directory.
Running in Xcode
You can also run this sample application inside Xcode. For more details, visit kitura.io.
This sample app is licensed under the Apache License, Version 2.0.
Help us keep the lights on
2.3.0 - Apr 23, 2018
- Update dependencies for Kitura 2.3 (#85)