2022-07-12 18:19:25 +00:00
|
|
|
# Implementing the client
|
|
|
|
|
2022-09-11 00:15:14 +00:00
|
|
|
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()`.
|
2022-07-12 18:19:25 +00:00
|
|
|
|
2022-09-11 00:15:14 +00:00
|
|
|
The first method will create a basic client without any headers or
|
|
|
|
customizations that aren't already in your OpenAPI specification file:
|
2022-07-12 18:19:25 +00:00
|
|
|
|
|
|
|
```rust
|
|
|
|
let client = Client::new("https://foo/bar");
|
|
|
|
```
|
|
|
|
|
2022-09-11 00:15:14 +00:00
|
|
|
Should you need to set custom headers or other `reqwest::ClientBuilder`
|
|
|
|
methods, you can use `Client::new_with_client()` as shown below.
|
2022-07-12 18:19:25 +00:00
|
|
|
|
|
|
|
```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);
|
|
|
|
```
|
|
|
|
|
2022-09-11 00:15:14 +00:00
|
|
|
For more information on available methods, see the
|
|
|
|
[reqwest](https://docs.rs/reqwest/latest/reqwest/struct.ClientBuilder.html)
|
|
|
|
documentation.
|