Skip to content

Commit

Permalink
Rename 'APIKey' in example docs to 'ApiKey'.
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioBenitez committed Jul 12, 2017
1 parent 0bbfa5e commit 70bc97c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
14 changes: 7 additions & 7 deletions lib/src/request/from_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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, ()));
Expand All @@ -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."
/// }
Expand Down
8 changes: 4 additions & 4 deletions site/overview.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 70bc97c

Please sign in to comment.