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
-
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
-
swift build
-
./.build/debug/Kitura-Sample
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.
Route: 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.
Route: localhost:8080/articles
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.
Route: localhost:8080/multi
Kitura supports multiple handlers per route, this example prints several lines to the window using different response.send()
methods.
Route: localhost:8080/users/:user
Note: This example uses :users
but you can use anything you like, as long as the first part of the route is /users/
.
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.
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.