From 70bc97c322362d084a603fa61908916ce04e72c9 Mon Sep 17 00:00:00 2001 From: Sergio Benitez Date: Wed, 12 Jul 2017 14:53:08 -0700 Subject: [PATCH] Rename 'APIKey' in example docs to 'ApiKey'. --- lib/src/request/from_request.rs | 14 +++++++------- site/overview.toml | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/src/request/from_request.rs b/lib/src/request/from_request.rs index ee91eb01..49192164 100644 --- a/lib/src/request/from_request.rs +++ b/lib/src/request/from_request.rs @@ -162,8 +162,8 @@ impl IntoOutcome for Result { /// requests be sent along with a valid API key in a header field. You want to /// ensure that the handlers corresponding to these requests don't get called /// unless there is an API key in the request and the key is valid. The -/// following example implements this using an `APIKey` type and a `FromRequest` -/// implementation for that type. The `APIKey` type is then used in the +/// following example implements this using an `ApiKey` type and a `FromRequest` +/// implementation for that type. The `ApiKey` type is then used in the /// `senstive` handler. /// /// ```rust @@ -175,17 +175,17 @@ impl IntoOutcome for Result { /// use rocket::http::Status; /// use rocket::request::{self, Request, FromRequest}; /// -/// struct APIKey(String); +/// struct ApiKey(String); /// /// /// Returns true if `key` is a valid API key string. /// fn is_valid(key: &str) -> bool { /// key == "valid_api_key" /// } /// -/// impl<'a, 'r> FromRequest<'a, 'r> for APIKey { +/// impl<'a, 'r> FromRequest<'a, 'r> for ApiKey { /// type Error = (); /// -/// fn from_request(request: &'a Request<'r>) -> request::Outcome { +/// fn from_request(request: &'a Request<'r>) -> request::Outcome { /// let keys: Vec<_> = request.headers().get("x-api-key").collect(); /// if keys.len() != 1 { /// return Outcome::Failure((Status::BadRequest, ())); @@ -196,12 +196,12 @@ impl IntoOutcome for Result { /// return Outcome::Forward(()); /// } /// -/// return Outcome::Success(APIKey(key.to_string())); +/// return Outcome::Success(ApiKey(key.to_string())); /// } /// } /// /// #[get("/sensitive")] -/// fn sensitive(key: APIKey) -> &'static str { +/// fn sensitive(key: ApiKey) -> &'static str { /// # let _key = key; /// "Sensitive data." /// } diff --git a/site/overview.toml b/site/overview.toml index 232cd774..c31e571e 100644 --- a/site/overview.toml +++ b/site/overview.toml @@ -89,15 +89,15 @@ request handler signature. Request guards _protect_ the handler from running unless some set of conditions are met by the incoming request metadata. For instance, if you are writing an API that requires sensitive calls to be accompanied by an API key in the request -header, Rocket can protect those calls via a custom `APIKey` request guard: +header, Rocket can protect those calls via a custom `ApiKey` request guard: ```rust #[get("/sensitive")] -fn sensitive(key: APIKey) -> &'static str { ... } +fn sensitive(key: ApiKey) -> &'static str { ... } ``` -`APIKey` protects the `sensitive` handler from running incorrectly. In order for -Rocket to call the `sensitive` handler, the `APIKey` type needs to be derived +`ApiKey` protects the `sensitive` handler from running incorrectly. In order for +Rocket to call the `sensitive` handler, the `ApiKey` type needs to be derived through a [FromRequest](https://api.rocket.rs/rocket/request/trait.FromRequest.html) implementation, which in this case, validates the API key header. Request guards