Coder Social home page Coder Social logo

fnet123 / kitura Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kitura/kitura

0.0 3.0 0.0 2.88 MB

A Swift web framework and HTTP server.

Home Page: http://www.kitura.io

License: Apache License 2.0

Makefile 0.29% Swift 93.38% Shell 3.03% Objective-C 0.23% HTML 1.76% CSS 0.83% Ruby 0.48%

kitura's Introduction

Kitura

A Swift Web Framework and HTTP Server

Build Status - Master macOS Linux Apache 2  Slack Status

Summary

Kitura is a web framework and web server that is created for web services written in Swift. For more information, visit www.kitura.io.

Table of Contents

Features

  • URL routing (GET, POST, PUT, DELETE)
  • URL parameters
  • Static file serving
  • FastCGI support
  • SSL/TLS support
  • JSON parsing
  • Pluggable middleware

Swift version

Version 1.0 of Kitura requires Swift 3.0. Kitura is unlikely to compile with any other version of Swift.

Installation

macOS

  1. Download and install Xcode 8.
  2. There is no step 2.

Now you are ready to develop your first Kitura app. Check Kitura-Sample or see Getting Started.

Note: if you have been using the Xcode 8 betas, you may also need to run sudo xcode-select -r to reset your selected developer directory.

Ubuntu Linux

Kitura is tested on Ubuntu 14.04 LTS and Ubuntu 15.10.

  1. Install the following system linux libraries:

$ sudo apt-get install libcurl4-openssl-dev uuid-dev

  1. Install the required Swift version from swift.org.

After installing it (i.e. extracting the .tar.gz 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.

Now you are ready to develop your first Kitura app. Check Kitura-Sample or see Getting Started.

Docker

  1. Install Docker on your development system.

  2. 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_kitura.sh script to build the Kitura-Starter-Bluemix sample project:

# /root/clone_build_kitura.sh

The last two output lines from executing the clone_build_kitura.sh script should be similar to:

Linking .build/debug/Kitura-Starter-Bluemix
>> Build for Kitura-Starter-Bluemix completed (see above for results).
  1. You can now run the Kitura-Starter-Bluemix executable inside the Docker container:

# /root/start_kitura_sample.sh

You should see an output message that contains the string Listening on port 8090.

Vagrant

  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.

Now you are ready to develop your first Kitura app. Check Kitura-Sample or see Getting Started.

Getting Started

Let's develop your first Kitura web application!

  1. First, create a new project directory.
$ mkdir myFirstProject
  1. Next, create a new Swift project using the Swift Package Manager.
$ cd myFirstProject
$ swift package init --type executable

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. In Package.swift, add Kitura as a dependency for your project.
import PackageDescription

let package = Package(
    name: "myFirstProject",
    dependencies: [
        .Package(url: "https://github.com/IBM-Swift/Kitura.git", majorVersion: 1, minor: 0)
    ])
  1. In Sources/main.swift, import the Kitura module.
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 and start the Kitura framework.
Kitura.addHTTPServer(onPort: 8090, with: router)
Kitura.run()
  1. Your 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 any problems that occur.

    Add a HeliumLogger dependency to Package.swift.

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

    Enable HeliumLogger in Sources/main.swift.

    import HeliumLogger
    
    HeliumLogger.use()

    Here is the finished Sources/main.swift file.

    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:

$ swift build

Or copy our 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

Contributing to Kitura

All improvements to Kitura are very welcome! Here's how to get started with developing Kitura itself.

  1. Clone this repository.

$ git clone https://github.com/IBM-Swift/Kitura

  1. Build and run tests.

$ make test

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

Community

We love to talk server-side Swift, and Kitura. Join our Slack to meet the team!

kitura's People

Contributors

bdhernand avatar dfirsht avatar dsperling avatar dylanneild avatar gilgs avatar grzegorzleszek avatar gtaban avatar ianpartridge avatar irar2 avatar kweinmeister avatar larssmit avatar mattcolegate avatar michalkalinowski- avatar na-gupta avatar naithar avatar nikitasullivan avatar pbohrer avatar rfdickerson avatar rob-deans avatar rolivieri avatar rsmoz avatar scottra avatar shmuelk avatar solidsnack avatar tardieu avatar tfrank64 avatar vadimeisenbergibm avatar yoseob avatar youming-lin avatar zzyyzz1992 avatar

Watchers

 avatar  avatar  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.