GithubHelp home page GithubHelp logo

adammendoza / kitura Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kitura/kitura

0.0 1.0 0.0 1.01 MB

A web framework and HTTP server for Swift

License: Apache License 2.0

Makefile 0.33% Swift 94.20% Objective-C 0.39% HTML 2.60% CSS 1.40% Ruby 1.08%

kitura's Introduction

Kitura

A Swift Web Framework and HTTP Server

Build Status - Master macOS Linux Apache 2 Join the chat at https://gitter.im/IBM-Swift/Kitura

Summary

Kitura is a web framework and web server that is created for web services written in Swift.

Table of Contents

Features:

  • URL routing (GET, POST, PUT, DELETE)
  • URL parameters
  • Static file serving
  • JSON parsing
  • Pluggable middleware

Swift version

This branch of Kitura requires the DEVELOPMENT-SNAPSHOT-2016-06-06-a version of Swift 3 trunk (master). You can download this version at swift.org. Kitura is unlikely to compile with any other version of Swift.

Installation (Docker development environment)

  1. Install Docker on your development system and start a Docker session/terminal.

  2. From the Docker session, pull down the kitura-ubuntu image from Docker Hub:

docker pull ibmcom/kitura-ubuntu:latest

  1. Create a Docker container using the kitura-ubuntu image you just downloaded and forward port 8090 on host to the container:

docker run -i -p 8090:8090 -t ibmcom/kitura-ubuntu:latest /bin/bash

  1. From within the Docker container, execute the clone_build_test_kitura.sh script to build Kitura and execute the test cases:

/root/clone_build_test_kitura.sh

The last output line from executing the clone_build_test_kitura.sh script should be similar to:

>> Finished execution of tests for Kitura (see above for results).

  1. You can now run the KituraSample executable inside the Docker container:

/root/start_kitura_sample.sh

You should see a message that says "Listening on port 8090".

Installation (Vagrant development environment)

  1. Install VirtualBox.

  2. Install Vagrant.

  3. From the root of the Kitura folder containing the vagrantfile, create and configure a guest machine:

vagrant up

  1. SSH into the Vagrant machine:

vagrant ssh

  1. As needed for development, edit the vagrantfile to setup Synced Folders to share files between your host and guest machine.

  2. Now you are ready to develop your first Kitura App. Check Kitura Sample or see Developing Kitura applications.

Installation (macOS)

  1. Install Homebrew (if you don't already have it installed):

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

  1. Install the necessary dependencies:

brew install curl

  1. Download and install the supported Swift compiler.

During installation if you are using the package installer make sure to select "all users" for the installation path in order for the correct toolchain version to be available for use with the terminal.

After installation, make sure you update your PATH environment variable as described in the installation instructions (e.g. export PATH=/Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin:$PATH)

  1. Now you are ready to develop your first Kitura App. Check Kitura Sample or see Developing Kitura applications.

Installation (Linux, Apt-based)

  1. Install the following system linux libraries:

sudo apt-get install autoconf libtool libkqueue-dev libkqueue0 libcurl4-openssl-dev libbsd-dev libblocksruntime-dev

  1. Install the supported Swift compiler for Linux.

Follow the instructions provided on that page. After installing it (i.e. uncompressing the tar file), make sure you update your PATH environment variable so that it includes the extracted tools: export PATH=/<path to uncompress tar contents>/usr/bin:$PATH. To update the PATH env variable, you can update your .bashrc file.

  1. Clone, build and install the libdispatch library. The complete instructions for building and installing this library are here, though, all you need to do is just this git clone --recursive -b experimental/foundation https://github.com/apple/swift-corelibs-libdispatch.git && cd swift-corelibs-libdispatch && sh ./autogen.sh && ./configure --with-swift-toolchain=<path-to-swift>/usr --prefix=<path-to-swift>/usr && make && make install

  2. Now you are ready to develop your first Kitura App. Check Kitura Sample or see Developing Kitura applications.

Developing Kitura applications

Let's develop our first Kitura Web Application written in Swift!

  1. First we create a new project directory
mkdir myFirstProject
  1. Next we initialize this project as a new Swift package project
cd myFirstProject
swift package init

Now your directory structure under myFirstProject should look like this:

  myFirstProject
  ├── Package.swift
  ├── Sources
  │   └── main.swift
  └── Tests
      └── empty
  

Note: For more information on the Swift Package Manager, go here

  1. Now we add Kitura as a dependency for your project (Package.swift):
import PackageDescription

let package = Package(
    name: "myFirstProject",
    dependencies: [
        .Package(url: "https://github.com/IBM-Swift/Kitura.git", majorVersion: 0, minor: 20)
    ])
  1. Import Kitura module in your code (Sources/main.swift):
import Kitura
  1. Add a router and a path:
let router = Router()

router.get("/") {
    request, response, next in
    response.send("Hello, World!")
    next()
}
  1. Add an HTTP Server to Kitura framework and start Kitura framework:
Kitura.addHTTPServer(onPort: 8090, with: router)
Kitura.run()
  1. Sources/main.swift file should now look like this:
import Kitura

let router = Router()

router.get("/") {
    request, response, next in
    response.send("Hello, World!")
    next()
}

Kitura.addHTTPServer(onPort: 8090, with: router)
Kitura.run()
  1. Optionally add logging

    In the code example above, no messages from Kitura will logged. You may want to add a logger to help diagnose problems that occur. This is completely optional, Kitura will run perfectly without a logger.

    You also need to add HeliumLogger to your Package.swift file. It should look like this:

    import PackageDescription
    let package = Package(
     name: "myFirstProject",
     dependencies: [
         .Package(url: "https://github.com/IBM-Swift/Kitura.git", majorVersion: 0, minor: 20),
         .Package(url: "https://github.com/IBM-Swift/HeliumLogger", majorVersion: 0, minor: 9),
     ])

    To add a logger simply add the following lines, after the import Kitura statement in the Sources/main.swift file shown above:

    import HeliumLogger
    
    HeliumLogger.use()

    The overall Sources/main.swift file would then be:

    import Kitura
    import HeliumLogger
    
    HeliumLogger.use()
    
    let router = Router()
    
    router.get("/") {
        request, response, next in
        response.send("Hello, World!")
        next()
    }
    
    Kitura.addHTTPServer(onPort: 8090, with: router)
    Kitura.run()
  2. Compile your application:

  • macOS: swift build
  • Linux: swift build -Xcc -fblocks

Or copy Makefile and build scripts to your project directory and run make build. You may want to customize this Makefile and use it for building, testing and running your application. For example, you can clean your build directory, refetch all the dependencies, build, test and run your application by running make clean refetch test run.

  1. Now run your new web application:
.build/debug/myFirstProject
  1. Open your browser at http://localhost:8090

Kitura Wiki

Feel free to visit our Wiki for our roadmap and some tutorials.

Developing Kitura

  1. Clone this repository, master branch git clone -b master https://github.com/IBM-Swift/Kitura
  2. Build and run tests make test

Notes

  • Homebrew by default installs libraries to /usr/local, if yours is different, change the path to find the curl library, in Kitura-Build/build/Makefile:

    SWIFTC_FLAGS = -Xswiftc -I/usr/local/include
    LINKER_FLAGS = -Xlinker -L/usr/local/lib

You can find info on contributing to Kitura in our contributing guidelines.

License

This library is licensed under Apache 2.0. Full license text is available in LICENSE.

kitura's People

Contributors

vadimeisenbergibm avatar dfirsht avatar rfdickerson avatar rolivieri avatar shmuelk avatar ianpartridge avatar naithar avatar irar2 avatar tfrank64 avatar nikitasullivan avatar dsperling avatar kweinmeister avatar dylanneild avatar pbohrer avatar michalkalinowski- avatar grzegorzleszek avatar scottra avatar cjwirth avatar frogcjn avatar seabaylea avatar chrisozenne avatar djones6 avatar nuclearace avatar solidsnack avatar larssmit avatar rsmoz avatar zzyyzz1992 avatar yoseob avatar mattcolegate avatar

Watchers

Adam J. Mendoza avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.