Document the JSON responder, default template dir.

This commit is contained in:
Sergio Benitez 2016-12-23 02:38:30 -08:00
parent b6e3cb6c05
commit e76ba7d219
2 changed files with 8 additions and 5 deletions

View File

@ -88,13 +88,16 @@ impl<T: Deserialize> FromData for JSON<T> {
}
}
// Serializes the wrapped value into JSON. Returns a response with Content-Type
// JSON and a fixed-size body with the serialization. If serialization fails, an
// `Err` of `Status::InternalServerError` is returned.
impl<T: Serialize> Responder<'static> for JSON<T> {
fn respond(self) -> response::Result<'static> {
serde_json::to_string(&self.0).map(|string| {
content::JSON(string).respond().unwrap()
}).map_err(|e| {
error_!("JSON failed to serialize: {:?}", e);
Status::BadRequest
Status::InternalServerError
})
}
}

View File

@ -25,10 +25,10 @@ use rocket::http::{ContentType, Status};
///
/// Templating in Rocket words by first discovering all of the templates inside
/// the template directory. The template directory is configurable via the
/// `template_dir` configuration parameter. The path set in `template_dir`
/// should be relative to the Rocket configuration file. See the [configuration
/// chapter](https://rocket.rs/guide/configuration) of the guide for more
/// information on configuration.
/// `template_dir` configuration parameter and defaults to `templates/`. The
/// path set in `template_dir` should be relative to the Rocket configuration
/// file. See the [configuration chapter](https://rocket.rs/guide/configuration)
/// of the guide for more information on configuration.
///
/// Templates are discovered according to their extension. At present, this
/// library supports the following templates and extensions: