Socket
Book a DemoInstallSign in
Socket

appex

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

appex

develop nodejs web services with the typescript programming language.

0.1.1
Source
npmnpm
Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

nodejs web services with the typescript programming language

install

npm install appex
  • overview
  • function signatures
  • function visibility
  • function routing
## overview

Appex is a nodejs web application and service framework built on top of the TypeScript programming language. Appex enables nodejs developers to expose typescript functions as http endpoints as well as generate meaningful service meta data for clients who consume them.

typescript

// program.ts

declare var require; 

// url: http://localhost:1337/
export function index (context:any): void { 
  
    context.response.write('home');

    context.response.end(); 
}

// url: http://localhost:1337/about
export function about (context:any): void { 
	
    context.response.write('about');

    context.response.end();
}

export module services {

    // url: http://localhost:1337/services/dir
    export function dir(context:any, path:string, callback:(contents:string[]) => void) {
        
        require('fs').readdir(path || './', (error, contents) => {
            
            callback(contents);

        });
    }
}

javascript

// app.js

var appex   = require('appex');

var runtime = appex.runtime ({ source : './program.ts', devmode : true });

require('http').createServer( function(request, response) {
    
    runtime(request, response);
    
}).listen(5444);
## function signatures

Appex supports two distinct function signatures. http handler signatures and json handler signatures.

### http handler signature

A http handler method can be created with the following function signature. The context argument contains the http request and response objects.

export function method(context:any) : void {

	context.response.write('hello world');
	
	context.response.end();

}
### json handler signature

A json handler function is a function which will automatically accept a HTTP POST'ed json string and pass it to the function as a object parameter. in addition, json handler functions also require that a response object be returned on the callback, which in turn will be passed back as a http response as a json string.

A http handler method can be created with the following function signature. The context argument contains the http request and response objects.

export function method(context:any, request:any, callback:(response:any) => void) {

	callback(request); // echo

}
## function routing

Appex creates url routing tables based on a function name and module scope. For example consider the following...

export function index   (context:any) { }

export function about   (context:any) { }

export function contact (context:any) { }

export module services.customers {

	export function insert(context:any) : void { }
	
	export function update(context:any) : void { }
	
	export function delete(context:any) : void { }
}

will create the following routes:

http://[host]:[port]/

http://[host]:[port]/about

http://[host]:[port]/contact

http://[host]:[port]/services/customers/insert

http://[host]:[port]/services/customers/update

http://[host]:[port]/services/customers/delete
## function visibility

Appex only exposes 'exported' functions over http. From this developers infer notions of public and private over http.

Consider the following example:


module private_module {

	export function public_method () {
	
		// this function is exported, but as this module is 
		
		// not exported, neither is this method.
	}
}

function private_function() {

	// this method is private
}

export function public_function   (context:any) { 

	private_function(); // ok
	
	private_module.public_method(); // ok
}

will result in the following routes.

http://[host]:[port]/public_function

Keywords

typescript

FAQs

Package last updated on 05 Jul 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.