Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 103 lines (70 sloc) 2.482 kB
dfa6330 @jsgoecke Added more content to the README
jsgoecke authored
1 Tropo WebAPI Node.js Library
2 ============================
3
f60bd8a @jsgoecke Added appropriate links to the readme and nixed some of the verbiage.
jsgoecke authored
4 A [Node.js](http://nodejs.org/ "Node.js") module for the [Tropo WebAPI](https://www.tropo.com/docs/webapi/ "Tropo WebAPI").
057b058 @mheadd Initial commit of module files and samples.
mheadd authored
5
dfa6330 @jsgoecke Added more content to the README
jsgoecke authored
6 Installation
7 ============
8
e185e2a @mheadd Modified install insutctions to reflect npm install
mheadd authored
9 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](http://howtonode.org/how-to-install-nodejs "Installing Node.js").
10
11
12 If you have Node.js installed, and are using the Node Package Manager (npm), just do:
13
68f50cc @chrismatthieu updated readme and and samples
authored
14 ~$ npm install tropo-webapi -g
e185e2a @mheadd Modified install insutctions to reflect npm install
mheadd authored
15
16 If you install with npm, then you can reference the tropo Node library in your node.js scripts like this:
17
18 <pre>
19 require('tropo-webapi');
20 </pre>
21
22 If you do not have npm installed, then you will then want to create a directory for your project, you may want to use a convention like this:
057b058 @mheadd Initial commit of module files and samples.
mheadd authored
23
24 <pre>
dfa6330 @jsgoecke Added more content to the README
jsgoecke authored
25 ./project
26 |-lib
27 |-public
28 |--css
29 |--js
30 |-vendor
31 </pre>
057b058 @mheadd Initial commit of module files and samples.
mheadd authored
32
68f50cc @chrismatthieu updated readme and and samples
authored
33 Add this declaration to your server.js starting file
057b058 @mheadd Initial commit of module files and samples.
mheadd authored
34
dfa6330 @jsgoecke Added more content to the README
jsgoecke authored
35 <pre>
68f50cc @chrismatthieu updated readme and and samples
authored
36 var tropowebapi = require('tropo-webapi');
dfa6330 @jsgoecke Added more content to the README
jsgoecke authored
37 </pre>
057b058 @mheadd Initial commit of module files and samples.
mheadd authored
38
dfa6330 @jsgoecke Added more content to the README
jsgoecke authored
39 Running
40 -------
41
42 You may then run your script from within the project directory with:
43
44 <pre>
45 node server.js
057b058 @mheadd Initial commit of module files and samples.
mheadd authored
46 </pre>
dfa6330 @jsgoecke Added more content to the README
jsgoecke authored
47
48 Sample Usage
49 ============
50
51 Generate a JSON Doc
52 -------------------
53
54 <pre>
68f50cc @chrismatthieu updated readme and and samples
authored
55 var tropowebapi = require('tropo-webapi');
dfa6330 @jsgoecke Added more content to the README
jsgoecke authored
56 var sys = require('sys');
57
68f50cc @chrismatthieu updated readme and and samples
authored
58 var tropo = new tropowebapi.TropoWebAPI();
dfa6330 @jsgoecke Added more content to the README
jsgoecke authored
59
60 tropo.say("Hello, World.");
61
68f50cc @chrismatthieu updated readme and and samples
authored
62 sys.puts(tropowebapi.TropoJSON(tropo));
dfa6330 @jsgoecke Added more content to the README
jsgoecke authored
63 </pre>
64
65 Respond to a Tropo WebAPI Session
66 ---------------------------------
67
68 <pre>
69 /**
70 * A very simple node web server that will respond to requests
71 * with the Tropo WebAPI JSON version of "Hello, World!"
72 */
73
74 var http = require('http');
68f50cc @chrismatthieu updated readme and and samples
authored
75 var tropowebapi = require('tropo-webapi');
dfa6330 @jsgoecke Added more content to the README
jsgoecke authored
76
77 var server = http.createServer(function (request, response) {
78
79 // Create a new instance of the TropoWebAPI object.
68f50cc @chrismatthieu updated readme and and samples
authored
80 var tropo = new tropowebapi.TropoWebAPI();
dfa6330 @jsgoecke Added more content to the README
jsgoecke authored
81 tropo.say("Hello, World!");
82
83 // Render out the JSON for Tropo to consume.
84 response.writeHead(200, {'Content-Type': 'application/json'});
68f50cc @chrismatthieu updated readme and and samples
authored
85 response.end(tropowebapi.TropoJSON(tropo));
dfa6330 @jsgoecke Added more content to the README
jsgoecke authored
86
87 }).listen(8000); // Listen on port 8000 for requests.
88 </pre>
89
90 Samples
91 =======
92
93 You may run the included samples from within the tropo-webapi-node directory as follows:
94
95 <pre>
96 node samples/hello-word-http.js
97 </pre>
98
99 We have also included several examples for the [Express.js](http://expressjs.com/ "Express.js") Node framework. This may be run from within the tropo-webapi-node library as follows:
100
101 <pre>
102 node samples/express/hello-world.js
103 </pre>
Something went wrong with that request. Please try again.