aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock25
-rw-r--r--Cargo.toml2
-rw-r--r--src/lib.rs7
-rw-r--r--tests/room_tests.rs2
4 files changed, 32 insertions, 4 deletions
diff --git a/Cargo.lock b/Cargo.lock
index d59d7c9..805a922 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -291,6 +291,11 @@ dependencies = [
]
[[package]]
+name = "itoa"
+version = "0.4.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
name = "kernel32-sys"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -577,6 +582,8 @@ dependencies = [
"r2d2 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)",
"rocket 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rocket_contrib_codegen 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -612,6 +619,11 @@ version = "0.1.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
+name = "ryu"
+version = "0.2.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
name = "safemem"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -638,6 +650,16 @@ version = "1.0.89"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
+name = "serde_json"
+version = "1.0.39"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "slab"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -874,6 +896,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum inotify-sys 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e74a1aa87c59aeff6ef2cc2fa62d41bc43f54952f55652656b18a02fd5e356c0"
"checksum iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08"
"checksum isatty 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e31a8281fc93ec9693494da65fbf28c0c2aa60a2eaec25dc58e2f31952e95edc"
+"checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b"
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
"checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a"
"checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14"
@@ -907,10 +930,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum rocket_contrib_codegen 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0d0d09f78854c63323184469446ffb34e808f7c99bd007ffc1542d371aeeec9a"
"checksum rocket_http 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ba9d4f2ce5bba6e1b6d3100493bbad63879e99bbf6b4365d61e6f781daab324d"
"checksum rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "adacaae16d02b6ec37fdc7acfcddf365978de76d1983d3ee22afc260e1ca9619"
+"checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7"
"checksum safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dca453248a96cb0749e36ccdfe2b0b4e54a61bfef89fb97ec621eb8e0a93dd9"
"checksum same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8f20c4be53a8a1ff4c1f1b2bd14570d2f634628709752f0702ecdd2b3f9a5267"
"checksum scheduled-thread-pool 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a2ff3fc5223829be817806c6441279c676e454cc7da608faf03b0ccc09d3889"
"checksum serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)" = "92514fb95f900c9b5126e32d020f5c6d40564c27a5ea6d1d7d9f157a96623560"
+"checksum serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)" = "5a23aa71d4a4d43fdbfaac00eff68ba8a06a51759a89ac3304323e800c4dd40d"
"checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
"checksum smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c4488ae950c49d403731982257768f48fada354a5203fe81f9bb6f43ca9002be"
"checksum state 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7345c971d1ef21ffdbd103a75990a15eb03604fc8b8852ca8cb418ee1a099028"
diff --git a/Cargo.toml b/Cargo.toml
index b9e3644..cb1b0de 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -11,4 +11,4 @@ rocket = "0.4.0"
[dependencies.rocket_contrib]
version = "0.4.0"
default-features = false
-features = ["serve", "diesel_postgres_pool"]
+features = ["json", "serve", "diesel_postgres_pool"]
diff --git a/src/lib.rs b/src/lib.rs
index 09e092c..e6bb0f6 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -19,12 +19,13 @@
use rocket::{
get,
- response::content::Json,
routes,
};
use rocket_contrib::{
database,
databases::diesel,
+ json,
+ json::JsonValue,
};
use std::collections::HashMap;
use std::error::Error;
@@ -34,8 +35,8 @@ use std::result::Result;
struct DbConn(diesel::PgConnection);
#[get("/")]
-fn get_rooms(_db: DbConn) -> Json<String> {
- Json("[]".into())
+fn get_rooms(_db: DbConn) -> JsonValue {
+ json!([])
}
pub fn build_rocket() -> Result<rocket::Rocket, Box<dyn Error>> {
diff --git a/tests/room_tests.rs b/tests/room_tests.rs
index 7415fd5..c91519d 100644
--- a/tests/room_tests.rs
+++ b/tests/room_tests.rs
@@ -17,11 +17,13 @@
*/
use ramaskrik;
+use rocket::http::ContentType;
#[test]
fn getting_rooms_from_api() {
let server = ramaskrik::build_rocket().unwrap();
let client = rocket::local::Client::new(server).unwrap();
let mut response = client.get("/rooms").dispatch();
+ assert_eq!(response.content_type(), Some(ContentType::JSON));
assert_eq!(response.body_string(), Some("[]".into()));
}