//extern crate rocket_contrib;
extern crate rocket;
extern crate mysql;
extern crate chrono;
extern crate serde_json;
use std::path::{Path, PathBuf};
use rocket_contrib::Template;
use rocket_contrib::{JSON, Value};
use rocket::response::NamedFile;
[dependencies]
rocket = "0.2.5"
rocket_codegen = "0.2.5"
mysql = "*"
chrono = "0.3"
serde = "0.9"
serde_json = "0.9"
serde_derive = "0.9"
error[E0432]: unresolved import rocket_contrib::JSON
--> src/main.rs:15:22
|
15 | use rocket_contrib::{JSON, Value};
| ^^^^ no JSON in the root
error[E0432]: unresolved import rocket_contrib::Value
--> src/main.rs:15:28
|
15 | use rocket_contrib::{JSON, Value};
| ^^^^^ no Value in the root
error: aborting due to 2 previous errors
Did you enable the json feature?
I had added =D
I am trying to (Serialize, Deserialize) date: chrono::NaiveDateTime it shows some errors
the trait bound chrono::NaiveDateTime: model::event::_IMPL_DESERIALIZE_FOR_Event::_serde::Serialize is not satisfied
I have another problem
fn not_found() -> Template {
let context = ();
Template::render("404", &context)
}
fn events() -> JSON
let pool = helper::DB::connection();
let selected_events = model::Event::all(pool);
println!("Events {:?}", selected_events);
JSON(selected_events)
}
fn main() {
rocket::ignite()
.mount("/", routes![files, index, events])
.catch(errors![not_found])
.launch();
}
the route is exist
馃洶 Mounting '/':
=> GET /
=> GET /events application/json
when I put in url http://localhost:8000/events I get 404 error
GET /events:
=> Matched: GET /None.
=> Outcome: Failure
=> Warning: Responding with 404 Not Found catcher.
=> Response succeeded.
Chrono has a "serde" feature that needs to be enabled before you can serialize their types.
[dependencies]
chrono = { version = "0.3", features = ["serde"] }
Looks like this has been answered. If you're still having issues, please feel free to comment. Better yet, join us on #rocket at irc.mozilla.org or via the bridged Rocket room on Matrix.
cool! I have a problem with generate json the route events return 404 =?
fn events() -> JSON
let pool = helper::DB::connection();
let selected_events = model::Event::all(pool);
println!("Events {:?}", selected_events);
JSON(selected_events)
}
fn main() {
rocket::ignite()
.mount("/", routes![files, index, events])
.catch(errors![not_found])
.launch();
}
GET /events:
=> Matched: GET /None.
=> Outcome: Failure
=> Warning: Responding with 404 Not Found catcher.
=> Response succeeded.
Most helpful comment
Chrono has a "serde" feature that needs to be enabled before you can serialize their types.