From 3c8c51260d49d66761899ce9c1bdfc13dbf04c2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karen=20C=C3=A1rcamo?= Date: Wed, 13 Jul 2022 06:19:25 +1200 Subject: [PATCH] Show how to use Client::new_with_client (#119) * Show how to use Client::new_with_client * new doc on implementation --- .gitignore | 2 +- docs/implementing-client.md | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 docs/implementing-client.md diff --git a/.gitignore b/.gitignore index ea8c4bf..2f7896d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -/target +target/ diff --git a/docs/implementing-client.md b/docs/implementing-client.md new file mode 100644 index 0000000..abd9116 --- /dev/null +++ b/docs/implementing-client.md @@ -0,0 +1,31 @@ +# Implementing the client + +Once you have generated your client, you'll notice there are two methods to create a new client; `Client::new()` and `Client::new_with_client()`. + +The first method will create a basic client without any headers or customisations that aren't already in your OpenAPI specification file: + +```rust +let client = Client::new("https://foo/bar"); +``` + +Should you need to set custom headers or other reqwest::ClientBuilder methods, you can use `Client::new_with_client()` as shown below. + +```rust +let mut val = reqwest::header::HeaderValue::from_static("super-secret"); +val.set_sensitive(true); +let mut headers = reqwest::header::HeaderMap::new(); +headers.insert(reqwest::header::AUTHORIZATION, val); +// Insert more headers if necessary + +let client_builder = reqwest::ClientBuilder::new() + // Set custom timeout + .connect_timeout(Duration::new(60, 0)) + // Set custom headers + .default_headers(headers) + .build() + .unwrap(); + +let client Client::new_with_client("https://foo/bar", client_builder); +``` + +For more information on available methods, see the [reqwest](https://docs.rs/reqwest/latest/reqwest/struct.ClientBuilder.html) documentation.