tropo-webapi-node

1.0.6 • Public • Published

Tropo WebAPI Node.js Library

A Node.js module for the Tropo WebAPI.

Installation

To get started you will first need to have Node.js installed. Howtonode has a good write-up on installing Node.js on Windows, Ubuntu and OSX. Next you will then want to create a directory for your project, you may want to use a convention like this:

	./project
	|-lib
	|-public
	|--css
	|--js
	|-vendor

Next copy the tropo-webapi-node/lib/tropo-webapi.js & tropo-webapi-node/lib/base.js in the project/lib directory. Then you may create a server.js file in the project directory that requires the Tropo WebAPI Node library as follows:

	require('../lib/tropo-webapi');

Running

You may then run your script from within the project directory with:

	node server.js

Sample Usage

Generate a JSON Doc

	require('../lib/tropo-webapi');
	var sys = require('sys');

	var tropo = new TropoWebAPI();

	tropo.say("Hello, World.");

	sys.puts(TropoJSON(tropo));

Respond to a Tropo WebAPI Session

	/**
	* A very simple node web server that will respond to requests
	* with the Tropo WebAPI JSON version of "Hello, World!" 
	*/

	var http = require('http');
	require('../lib/tropo-webapi');

	var server = http.createServer(function (request, response) {

		// Create a new instance of the TropoWebAPI object.
		var tropo = new TropoWebAPI();
		tropo.say("Hello, World!");

		// Render out the JSON for Tropo to consume.
		response.writeHead(200, {'Content-Type': 'application/json'});
		response.end(TropoJSON(tropo));

	}).listen(8000); // Listen on port 8000 for requests.

Samples

You may run the included samples from within the tropo-webapi-node directory as follows:

	node samples/hello-word-http.js

We have also included several examples for the Express.js Node framework. This may be run from within the tropo-webapi-node library as follows:

	node samples/express/hello-world.js

Readme

Keywords

none

Package Sidebar

Install

npm i tropo-webapi-node

Weekly Downloads

3

Version

1.0.6

License

none

Last publish

Collaborators

  • mheadd