Skip to content

Instantly share code, notes, and snippets.

@lian
Created May 26, 2009 08:55
Show Gist options
  • Select an option

  • Save lian/117965 to your computer and use it in GitHub Desktop.

Select an option

Save lian/117965 to your computer and use it in GitHub Desktop.
// $ curl http://localhost:8090/hello/world
{
"hello" : "world!",
"log" : "BackgroundColor changed, wohooo!"
}
//== API Syntax Choices
/* -----------------------------------------------------
------------------------ 1 -------------------------- */
void setup_em() {
em_thread.start();
em_thread.map_HttpRequest("/hello/world", this, &testApp::onHelloWorld );
}
void onHelloWorld(HttpRequest & _r) {
cout << "--GET /hello/world: \n" << json_writer.write(_r.params) << "\n";
ofBackground( ofRandom(0,255),ofRandom(0,255),ofRandom(0,255) );
Json::Value _v;
_v["hello"] = "world!";
_v["foobar"] = "BackgroundColor changed, wohooo!";
_r.fire(_v);
}
/* -----------------------------------------------------
------------------------ 2 -------------------------- */
void setup_em() {
em_thread.start();
em_thread.http.map("/hello/world", this, &testApp::onHelloWorld );
}
void onHelloWorld(HttpRequest & _r) {
cout << "--GET /hello/world: \n" << json_writer.write(_r.params) << "\n";
ofBackground( ofRandom(0,255),ofRandom(0,255),ofRandom(0,255) );
_r["response"]["hello"] = "world!";
_r["response"]["foobar"] = "BackgroundColor changed, wohooo!";
_r.fire( _r["response"] );
}
/* -----------------------------------------------------
------------------------ 3 -------------------------- */
void setup_em() {
em_thread.start();
em_thread.http.GET("/hello/world", this, &testApp::onHelloWorld );
}
void onHelloWorld(HttpRequest & _r) {
cout << "--GET /hello/world: \n" << json_writer.write(_r.params) << "\n";
ofBackground( ofRandom(0,255),ofRandom(0,255),ofRandom(0,255) );
_r["response"]["hello"] = "world!";
_r["response"]["foobar"] = "BackgroundColor changed, wohooo!";
_r.send_response();
// pass custom created Json::Value responses..
// _r.send_response( _r["response"] );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment