Skip to content

Commit

Permalink
RUST
Browse files Browse the repository at this point in the history
  • Loading branch information
tuck1s committed Jul 5, 2020
1 parent 1957970 commit 5fdbc03
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
4 changes: 4 additions & 0 deletions snippets/recipient-validation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ If you build and execute the code included in the repo, the result should look l
{"results":{"valid":true,"is_role":false,"is_disposable":false,"is_free":true,"result":"neutral"}}
```

## [Rust](rust_recipient_validation/src/main.rs)

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.

## 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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use reqwest;
use std::env;
use tokio;
//use std::collections::HashMap;

#[tokio::main]
async fn main() -> Result<(), reqwest::Error> {
Expand All @@ -15,15 +14,18 @@ async fn main() -> Result<(), reqwest::Error> {
// API key from environment variable. Should have Recipient Validation rights
match env::var("SPARKPOST_API_KEY") {
Ok(api_key) => {
println!("{:#?} {:#?} {:#?}", url, api_key, recipient);

let req_url = String::from(url) + recipient;
// h = {'Authorization': apiKey, 'Accept': 'application/json'}

let client = reqwest::Client::new();
let resp = client.get(&req_url).send().await?;
// .json::<HashMap<String, String>>()
println!("{:#?}", resp);
let res = client
.get(&req_url)
.header("Authorization", api_key)
.header("Accept", "application/json")
.send()
.await?;

println!("Status: {}", res.status());
let body = res.text().await?;
println!("Body:\n{}", body);
}
Err(e) => {
println!("SPARKPOST_API_KEY {}", e);
Expand Down

0 comments on commit 5fdbc03

Please sign in to comment.