Skip to content

Commit

Permalink
More Rust README
Browse files Browse the repository at this point in the history
  • Loading branch information
tuck1s committed Jul 6, 2020
1 parent 13a2a7d commit 88968e8
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion snippets/recipient-validation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ If you build and execute the code included in the repo, the result should look l

This uses the `reqwest` library with `tokio` async (similar to [this](https://rust-lang-nursery.github.io/rust-cookbook/web/clients/requests.html)), as it does not seem possible to set request headers on the blocking `get` call.

The example includes a cargo package manager [configuration file](rust_recipient_validation/Cargo.toml), so you can build and run with:`
The example includes a cargo package manager [configuration file](rust_recipient_validation/Cargo.toml), so you can build and run with:

```
cd rust_recipient_validation
Expand All @@ -218,6 +218,10 @@ Body:
{"results":{"valid":false,"is_role":true,"is_disposable":false,"is_free":true,"reason":"Invalid Recipient","result":"undeliverable"}}
```

The code uses `std:env` to read the `SPARKPOST_API_KEY` environment variable. A `match` clause handles an undefined key with error reporting. A new `reqwest::Client` is created and an async call issued, followed by an `.await?` (see [here](https://rust-lang.github.io/async-book/01_getting_started/04_async_await_primer.html)). This (rather than the simpler blocking call) seems to be needed to set the request header for authorization.

Response body text is read with a second `.await?` as per [this example](https://dtantsur.github.io/rust-openstack/reqwest/struct.Response.html).

## Summary
You made is this far, you earn the honorary badge of [Codefox 🦊](https://en.wikipedia.org/wiki/The_Hedgehog_and_the_Fox)!

Expand Down

0 comments on commit 88968e8

Please sign in to comment.