Permalink
Browse files

added node.js example

  • Loading branch information...
1 parent 7f0ce22 commit 65742aa882278bada3ce0dd3ab8547b68b91f80f @joshbuddy committed Jan 18, 2010
Showing with 32 additions and 0 deletions.
  1. +32 −0 README.rdoc
View
@@ -119,3 +119,35 @@ Any extra variables used as params would be appended as part of the query string
Would return
"/test2/variable.html?page=1"
+
+== Node.js
+
+To use this within Node.js, simply use the Node.js interface. Here is a simple example:
+
+ require('../lib/sherpa')
+
+ var sys = require("sys"), http = require("http");
+ var sherpa = new Sherpa.interfaces.NodeJs({
+ '/hello': {to: function (request, response) {
+ response.sendHeader(200, {"Content-Type": "text/plain"});
+ response.sendBody("Hello World\n");
+ response.finish();
+ }},
+ '/hello/:name': {to: function (request, response) {
+ response.sendHeader(200, {"Content-Type": "text/plain"});
+ response.sendBody("Hello "+request.sherpa_response.params['name']+"\n");
+ response.finish();
+ }},
+ 'not found': {to: function (request, response) {
+ response.sendHeader(404, {"Content-Type": "text/plain"});
+ response.sendBody("I can't find what you're looking for..");
+ response.finish();
+ }}
+
+ });
+
+ http.createServer(sherpa.listener()).listen(8000);
+ sys.puts("Server running at http://127.0.0.1:8000/");
+
+Then calling to <tt>/hello</tt> would produce <tt>Hello World</tt>, <tt>/hello/daniel</tt> would produce <tt>Hello daniel</tt> and any other request would respond with a 404 and <tt>I can't find what you're looking for..</tt>.
+

0 comments on commit 65742aa

Please sign in to comment.