Created
October 15, 2011 22:37
-
-
Save dyoder/1290244 to your computer and use it in GitHub Desktop.
Adapter code cleans up nicely in CoffeeScript ...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env coffee | |
Server = require("../../lib/shark/http_server") | |
Adapter = require("../../lib/shark/http_adapter") | |
configuration = require("../conf/server.conf") | |
configuration.processor = (server) -> | |
adapter = new Adapter(server) | |
adapter.resource "bar","/foo/:bar", (adapter) -> | |
adapter.version "1.0", (adapter) -> | |
adapter.method "get", (adapter) -> | |
adapter.accept "application/json", (adapter) -> | |
adapter.run -> | |
this.emit "ok", this.workspace.captured | |
adapter.method "post", (adapter) -> | |
adapter.accept "application/json", (adapter) -> | |
adapter.contentType "application/json", (adapter) -> | |
adapter.run (data) -> | |
this.emit "created", data | |
return adapter.processor(); | |
Server.run(configuration); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
var Server = require("../../lib/shark/http_server") | |
, configuration = require("../conf/server.conf") | |
, Adapter = require("../../lib/shark/http_adapter") | |
; | |
configuration.processor = function(server) { | |
var adapter = new Adapter(server); | |
adapter.resource("bar","/foo/:bar",function(adapter) { | |
adapter.version("1.0",function(adapter) { | |
adapter.method("get",function(adapter) { | |
adapter.accept("application/json",function(adapter){ | |
adapter.run(function(){ | |
this.emit("ok",this.workspace.captured); | |
}); | |
}); | |
}); | |
adapter.method("post",function(adapter) { | |
adapter.accept("application/json", function(adapter) { | |
adapter.contentType("application/json", function(adapter) { | |
adapter.run(function(data) { | |
this.emit("created",data); | |
}); | |
}); | |
}); | |
}); | |
}); | |
}); | |
return adapter.processor(); | |
}; | |
Server.run(configuration); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment