0.7.1 • Published 4 days ago

canis v0.7.1

Weekly downloads
8
License
ISC
Repository
github
Last release
4 days ago

Canis, Node.js based RESTful web service for Orion project.

Introduction

Orion ( http://orionids.org ) project is aimed to be a general purpose application framework which supports various forms of application including web app.

So Canis is a part of Orion project and will support :

  • RESTful web service framework, compatible to various cloud services including AWS API gateway. ( initial implementation is done )
  • API definition using JSON and automatic API hirarchy generation for AWS. ( initial implementation is done )
  • Supports popular web app frameworks like Express. ( Partial implementation for express is done )

New features in 0.1.0 to 0.4.4

  • AWS related - Functions needed to generate AWS APIs and methods automatically according to api.json - property names begin with ^ or /^ are excluded from auto generation - Bug fixes for header mapping - AWS proxy support - AWS proxy style input support ( when AWS proxy is not used ) - requestContext and pathParameters are used to maintain compatibility with lambda proxy integration - Delay and retry to call APIs in AWS SDK ( https://docs.aws.amazon.com/apigateway/latest/developerguide/limits.html ) - Wrapper functions for DynamoDB.DocumentClient ( partition key query, primary key query, update expression, delete queried results ) - AWS compatibility ( very early implementation )
  • REST API server related - Stage support in api.json - API key support - Custom interactive command - Client socket management - Static page support - Multiple API sets
  • Utilities related - delimiters to define a symbol is changed from {} to [] because {} is used to define path parameters - custom delimiters can be specified to resolve symbols - Command line option processor - Some examples are added - On demand symbol resolve ( test/resolve.js ) - request.js is added to call APIs various way ( basically test purpose ) - request iteration - some implementations to support mock - invoke.js to support various function call - storage.js - to support various storage access using compatible functions - Memory DB to simulate specific storage state using compatible API - Compatible synchronization method - S3 support - object.js, string.js : some utility functions related to objects & strings

Known todo list

  • Static files
  • https support
  • Done(0.3.2) : An implementation like AWS lambda proxy integration ( AWS API auto generation already supports this option )
  • Conditional storage operation compatible to AWS DynamoDB
  • User account support using popular frameworks
  • Interoperability with Orion project

Examples are added

  • test/itertest.js : how to use canis iterator including aynchronous execution case
  • test/match.js : find the matching API ( to run this, cwd must be canis/test )
  • test/server.js : run an REST API server according to test/testapi.js - to run this, cwd must be canis/test - after executing this, access http://127.0.0.1:5000/test1/hello in a web browser - API key can be enabled in test/testapi.js ( API cannot be called in a web browser )
  • test/unique.js : Unique time generation

Usage

You should create a file api.json or api.js in current working direcrory and run node canis_path/server.js ( Current implementation temporarily listens port 3000 for test )

An example of api.js which necessarily exports body is below. If there is stage property in global configuration, API URL will be base_url/stage_name/path and the current stage will be automatically passed to the context of lambda handler - for AWS API auto-generation feature in Canis, header mapping contains similar code to do that :

exports.body = {
	"configuration" : {
		"stage" : {
			"test1" : {
				"comment" : "A test stage",
				"apiKey" : "abcd"
			}
		},
		"apiKeyRequired" : true,
		"lambdaPrefix" : "",
		// optional aws specific parameters
		"aws-gatewayRegion" : "ca-central-1",
		"aws-lambdaRegion" : ""
	},
	"/hello" : {
		"/{param1}" : {
			"GET" : {
				"lambda" : "lambda/param1",
			},
			"/world" : {
				"/{param2}" : {
					"POST" : {
						"lambda" : "lambda/param2"
					}
				}
			}
		},
		"GET" : {
			"lambda" : "lambda/hello",
			"lambdaName" : "sayHello"
		},
		"/world" : {
			"GET" : {
				"lambda" : "lambda/world"
			}
		}
	}
};

An example to generate AWS API automatically

const server = require( "canis/server" );
const awsapi = require( "canis/awsapi" );

// myapi.js ( with exported body )  or myapi.json must be present in cwd
server.main( "myapi", function( api, cwd ) {
	if ( api ) {
		var iter = new awsapi.iterator(
			function( iter, code, data ) { // progress callback
				switch ( code ) {
					case undefined:
					console.log( "Done." );
					break;
					case -1: // an error
					console.log( data );
					break;
					case awsapi.PATH:
					console.log( iter.path + data );
					break;
					case awsapi.METHOD:
					console.log( data );
					break;
					case awsapi.EXISTING_METHOD:
					data = iter.path + "/" + data;
					case awsapi.EXISTING_PATH:
					console.log( data + " : present" );
					break;
				}
			}
		);
		awsapi.createAPI( iter, api,
			"my-api-set-[stage]", // rest api name with symbol 'stage'
			[process.env], // array of key-value pairs to resolve symbol defined by {symbol}
			null, // subset path : if path is not null but subset json is null,
			      // try to match path using given parameter 'api' ( first param )
			null, // subset json );
	} else {
		console.log( "No API definition." );
	}
} );
0.7.1

4 days ago

0.7.0

16 days ago

0.5.8

8 months ago

0.6.2

6 months ago

0.6.1

6 months ago

0.5.7

1 year ago

0.5.4

2 years ago

0.5.6

2 years ago

0.5.5

2 years ago

0.5.3

3 years ago

0.5.2

3 years ago

0.5.1

3 years ago

0.5.0

3 years ago

0.4.4

5 years ago

0.4.3

5 years ago

0.4.2

5 years ago

0.4.1

5 years ago

0.4.0

5 years ago

0.3.4

5 years ago

0.3.3

5 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago