Next generation web framework for building APIs

Kite focus on writing APIs more efficiently with latest Javascript features

Current version 0.5.10:

Introduction

Kite is a lightweight web application framework, it's designed for efficient coding of APIs. Here are differences between other hot frameworks ( ExpressJS, KoaJS):

Use Kite cli tools to quickly start your application!

                
npm i kite-tools -g
kite --help
                
            

Quick start

Create a kite project:

        
kite -p --yes first-kite-app
        
    

Explanation for the upper command:

Then Kite CLI tools will create a folder first-kite-app, initialize the project folder with some files and directories, install NodeJS dependencies as well.

Making Kite fly

If the above steps finished without error (generally network problems), now you can enter the project folder, and start Kite application server:

            
cd first-kite-app
npm start
            
        

After a few seconds waiting for TypeScript compilation / NodeJS running, you'll see a message like:

        
2018-3-23 10:13:24 [ KITE ] Flying! server listening at 127.0.0.1:4000
        
    

which means Kite application server is successfully started, then open a browser window and visit 127.0.0.1:4000(or localhost:4000), you will get a message like:

        
{"error":{"code":1002,"msg":"Resource not found"}}
        
    

don't worry about this error message, it's just means the request resource / was not found on server, your application just works great.

First API

Using kite-tools, you can easily create Kite APIs. Open a new terminal (keep previous terminal running, which servicing your application), under project folder type this command:

        
kite -a greet
        

Kite CLI tools will generate a file named greet.controller.ts under src/controllers/ folder, it looks like this:

        
import { Controller, Entry, KiteError, Inject } from 'kite-framework';

@Controller()
export class GreetController {
    @Entry()
    async exec() {
        throw new KiteError(1000, 'this api is not implemented');
    }
}
        
        

then run command tsc to compile this TypeScript source:

        
tsc
        

Now you can try this API by visiting http://localhost:4000/greet, here is the response:

{"error":{"code":1000,"msg":"this api is not implemented"}}

Hello world! (plain text output)

Simply returns a string from APIs will cause the framework outputs content in text/plain type. API source greet.controller.ts example:

        
import { Controller, Entry, KiteError, Inject } from 'kite-framework'; 

@Controller() export class GreetController { 
    @Entry()
    async exec() { 
        return "hello world!"; 
    } 
}
        
    

Save and run tsc to compile ( boring with typing tsc everytime? open a new terminal and try tsc -w, see TypeScript compiler watch mode ).

Now refresh the page( http://localhost:4000/greet), response:

        
hello world!
        

Hello world! (json output)

KiteJS is a framework focusing on web APIs, an API is generally output a JSON formatted string, and in JavaScript/NodeJs, why not JSON?

Returns an object from APIs will cause the framework outputs content in application/json type. API source greet.controller.ts example:

        
import { Controller, Entry, KiteError, Inject } from 'kite-framework';

@Controller()
export class GreetController {
    @Entry()
    async exec() {
        return { msg: "hello world!" };
    }
}
        
    

Compile the source (if not running tsc -w) and refresh the page, response like:

        
{"msg":"hello world!"}
        

Accepting client parameters

Declared arguments in Kite entry point function ( exec() as of yet) is mapped to client parameters by KiteJS framework at controller loading time.

Here is an example (create a new controller welcome.controller.ts by kite-tools kite -a welcome):

        
import { Controller, Entry, KiteError, Inject } from 'kite-framework';

@Controller()
export class WelcomeController {
    @Entry()
    async exec(name: string) {
        return { msg: `Hello, ${name}!` };
    }
}
        
    

Compile the source (if not running tsc -w), and visit http://localhost:4000/welcome?name=Kite, response like:

        
{"msg":"Hello, Kite!"}