Rename 'APIKey' in example docs to 'ApiKey'.

This commit is contained in:
Sergio Benitez 2017-07-12 14:53:08 -07:00
parent 0bbfa5e21a
commit 70bc97c322
2 changed files with 11 additions and 11 deletions

View File

@ -162,8 +162,8 @@ impl<S, E> IntoOutcome<S, (Status, E), ()> for Result<S, E> {
/// 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<S, E> IntoOutcome<S, (Status, E), ()> for Result<S, E> {
/// 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<APIKey, ()> {
/// fn from_request(request: &'a Request<'r>) -> request::Outcome<ApiKey, ()> {
/// let keys: Vec<_> = request.headers().get("x-api-key").collect();
/// if keys.len() != 1 {
/// return Outcome::Failure((Status::BadRequest, ()));
@ -196,12 +196,12 @@ impl<S, E> IntoOutcome<S, (Status, E), ()> for Result<S, E> {
/// 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."
/// }

View File

@ -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