Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes post_service example by adding TLS #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ features = ["client", "hyper"]

[dev-dependencies]
serde_derive = "1.0"
hyper-native-tls = "0.3.0"

[features]
default = ["json", "xml"]
Expand Down
11 changes: 9 additions & 2 deletions examples/post_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
// instead of `Deserialize` and `Serialize`, respectively.

#[macro_use] extern crate anterofit;
extern crate hyper_native_tls;
#[macro_use] extern crate serde_derive;

// The minimum imports needed to get this example working.
//
// You can glob-import if you like, but know that it will shadow `Result`
// which may cause some confusing type-mismatch errors.
use anterofit::{Adapter, Url};
use anterofit::{Adapter, Url, hyper::{net::HttpsConnector, Client}};
use hyper_native_tls::NativeTlsClient;

#[derive(Debug, Deserialize)]
struct Post {
Expand Down Expand Up @@ -69,8 +71,13 @@ fn main() {
// Navigate to this URL in your browser for details. Very useful test API.
let url = Url::parse("https://jsonplaceholder.typicode.com").unwrap();

let ssl = NativeTlsClient::new().unwrap();
let connector = HttpsConnector::new(ssl);
let client = Client::with_connector(connector);

let adapter = Adapter::builder()
.base_url(url)
.client(client)
// When your REST API uses JSON in both requests and responses
.serialize_json()
.build();
Expand Down Expand Up @@ -116,4 +123,4 @@ fn user_posts(post_service: &PostService) {
// This will be executed asynchronously when the request is completed
.on_complete(|posts| for post in posts { println!("User post: {:?}", post); })
.exec().ignore();
}
}