Refactoring dapps to support API endpoints. (#1542)

* Refactoring dapps to support API endpoints.

* Using ContentHandler for unauthorized requests
This commit is contained in:
Tomasz Drwięga
2016-07-06 05:24:29 -04:00
committed by Gav Wood
parent bcb63bce12
commit a8b26e2cb5
15 changed files with 291 additions and 173 deletions

View File

@@ -16,8 +16,13 @@
use serde::Serialize;
use serde_json;
use endpoint::{ContentHandler, Handler};
use endpoint::Handler;
use handlers::ContentHandler;
pub fn as_json<T : Serialize>(val: &T) -> Box<Handler> {
Box::new(ContentHandler::new(serde_json::to_string(val).unwrap(), "application/json".to_owned()))
Box::new(ContentHandler::ok(serde_json::to_string(val).unwrap(), "application/json".to_owned()))
}
pub fn as_json_error<T : Serialize>(val: &T) -> Box<Handler> {
Box::new(ContentHandler::not_found(serde_json::to_string(val).unwrap(), "application/json".to_owned()))
}