Skip to content

Instantly share code, notes, and snippets.

@dyoder
Created October 15, 2011 22:37
Show Gist options
  • Save dyoder/1290244 to your computer and use it in GitHub Desktop.
Save dyoder/1290244 to your computer and use it in GitHub Desktop.
Adapter code cleans up nicely in CoffeeScript ...
#!/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);
#!/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