Skip to content

Commit fadfa9b

Browse files
alexeyzimarevclaude
andcommitted
Fix code snippets in docs: Uri type, semicolons, property names, example constructor
- Fix `new Url(...)` to `new Uri(...)` in configuration example - Remove stray semicolon in serialization lambda example - Replace deprecated `MaxTimeout` with `Timeout` in client docs - Replace `BaseAddress` with `BaseUrl` in HttpClient reuse section - Fix example constructor to use `RestClientOptions` instead of `IOptions<>` Co-Authored-By: Claude Opus 4.6 <[email protected]>
1 parent 0bf3619 commit fadfa9b

8 files changed

Lines changed: 34 additions & 20 deletions

File tree

docs/docs/advanced/configuration.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ For example:
6262

6363
```csharp
6464
var client = new RestClient(options => {
65-
options.BaseUrl = new Url("https://localhost:5000/api"),
66-
options.DisableCharset = true
65+
options.BaseUrl = new Uri("https://localhost:5000/api");
66+
options.DisableCharset = true;
6767
});
6868
```
6969

docs/docs/advanced/serialization.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ You can tell RestSharp to use a custom serializer by using the `configureSeriali
1616
```csharp
1717
var client = new RestClient(
1818
options,
19-
configureSerialization: s => s.UseSerializer(() => new CustomSerializer());
19+
configureSerialization: s => s.UseSerializer(() => new CustomSerializer())
2020
);
2121
```
2222

docs/docs/usage/client.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Here's an example of how to create a client using the same base path as in the p
2424
```csharp
2525
// Creates a client using the options object
2626
var options = new RestClientOptions("https://localhost:5000") {
27-
MaxTimeout = 1000
27+
Timeout = TimeSpan.FromSeconds(1)
2828
};
2929
var client = new RestClient(options);
3030
```
@@ -47,7 +47,7 @@ Another way to create the client instance is to use a simple client factory. The
4747
* `RemoteCertificateValidationCallback`
4848
* `ClientCertificates`
4949
* `MaxRedirects`
50-
* `MaxTimeout`
50+
* `Timeout`
5151
* `UserAgent`
5252
* `Expect100Continue`
5353

@@ -66,8 +66,8 @@ RestSharp uses `HttpClient` internally to make HTTP requests. It's possible to r
6666

6767
One way of doing it is to use `RestClient` constructors that accept an instance of `HttpClient` or `HttpMessageHandler` as an argument. Note that in that case not all the options provided via `RestClientOptions` will be used. Here is the list of options that will work:
6868

69-
- `BaseAddress` is be used to set the base address of the `HttpClient` instance if base address is not set there already.
70-
- `MaxTimeout` is used to cancel the call using the cancellation token source, so
69+
- `BaseUrl` will be taken from `httpClient.BaseAddress` if not set explicitly.
70+
- `Timeout` is used to cancel the call using the cancellation token source.
7171
- `UserAgent` will be added to the `RestClient.DefaultParameters` list as a HTTP header. This will be added to each request made by the `RestClient`, and the `HttpClient` instance will not be modified. This is to allow the `HttpClient` instance to be reused for scenarios where different `User-Agent` headers are required.
7272
- `Expect100Continue`
7373

docs/docs/usage/example.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,18 @@ public class TwitterClient : ITwitterClient, IDisposable {
7676
It is also possible to use ASP.NET Core Options for configuring the client, instead of passing the credentials as strings. For example, we can add a class for Twitter client options, and use it in a constructor:
7777

7878
```csharp
79-
public class TwitterClientOptions(string ApiKey, string ApiSecret);
79+
public record TwitterClientOptions(string ApiKey, string ApiSecret);
8080

8181
public TwitterClient(IOptions<TwitterClientOptions> options) {
82-
var opt = new RestClientOptions("https://api.twitter.com/2");
83-
_client = new RestClient(options);
82+
var tokenRequest = new OAuth2TokenRequest(
83+
"https://api.twitter.com/oauth2/token",
84+
options.Value.ApiKey,
85+
options.Value.ApiSecret
86+
);
87+
var opt = new RestClientOptions("https://api.twitter.com/2") {
88+
Authenticator = new OAuth2ClientCredentialsAuthenticator(tokenRequest)
89+
};
90+
_client = new RestClient(opt);
8491
}
8592
```
8693

docs/versioned_docs/version-v114/advanced/configuration.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ For example:
6262

6363
```csharp
6464
var client = new RestClient(options => {
65-
options.BaseUrl = new Url("https://localhost:5000/api"),
66-
options.DisableCharset = true
65+
options.BaseUrl = new Uri("https://localhost:5000/api");
66+
options.DisableCharset = true;
6767
});
6868
```
6969

docs/versioned_docs/version-v114/advanced/serialization.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ You can tell RestSharp to use a custom serializer by using the `configureSeriali
1616
```csharp
1717
var client = new RestClient(
1818
options,
19-
configureSerialization: s => s.UseSerializer(() => new CustomSerializer());
19+
configureSerialization: s => s.UseSerializer(() => new CustomSerializer())
2020
);
2121
```
2222

docs/versioned_docs/version-v114/usage/client.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Here's an example of how to create a client using the same base path as in the p
2424
```csharp
2525
// Creates a client using the options object
2626
var options = new RestClientOptions("https://localhost:5000") {
27-
MaxTimeout = 1000
27+
Timeout = TimeSpan.FromSeconds(1)
2828
};
2929
var client = new RestClient(options);
3030
```
@@ -47,7 +47,7 @@ Another way to create the client instance is to use a simple client factory. The
4747
* `RemoteCertificateValidationCallback`
4848
* `ClientCertificates`
4949
* `MaxRedirects`
50-
* `MaxTimeout`
50+
* `Timeout`
5151
* `UserAgent`
5252
* `Expect100Continue`
5353

@@ -66,8 +66,8 @@ RestSharp uses `HttpClient` internally to make HTTP requests. It's possible to r
6666

6767
One way of doing it is to use `RestClient` constructors that accept an instance of `HttpClient` or `HttpMessageHandler` as an argument. Note that in that case not all the options provided via `RestClientOptions` will be used. Here is the list of options that will work:
6868

69-
- `BaseAddress` is be used to set the base address of the `HttpClient` instance if base address is not set there already.
70-
- `MaxTimeout` is used to cancel the call using the cancellation token source, so
69+
- `BaseUrl` will be taken from `httpClient.BaseAddress` if not set explicitly.
70+
- `Timeout` is used to cancel the call using the cancellation token source.
7171
- `UserAgent` will be added to the `RestClient.DefaultParameters` list as a HTTP header. This will be added to each request made by the `RestClient`, and the `HttpClient` instance will not be modified. This is to allow the `HttpClient` instance to be reused for scenarios where different `User-Agent` headers are required.
7272
- `Expect100Continue`
7373

docs/versioned_docs/version-v114/usage/example.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,18 @@ public class TwitterClient : ITwitterClient, IDisposable {
7676
It is also possible to use ASP.NET Core Options for configuring the client, instead of passing the credentials as strings. For example, we can add a class for Twitter client options, and use it in a constructor:
7777

7878
```csharp
79-
public class TwitterClientOptions(string ApiKey, string ApiSecret);
79+
public record TwitterClientOptions(string ApiKey, string ApiSecret);
8080

8181
public TwitterClient(IOptions<TwitterClientOptions> options) {
82-
var opt = new RestClientOptions("https://api.twitter.com/2");
83-
_client = new RestClient(options);
82+
var tokenRequest = new OAuth2TokenRequest(
83+
"https://api.twitter.com/oauth2/token",
84+
options.Value.ApiKey,
85+
options.Value.ApiSecret
86+
);
87+
var opt = new RestClientOptions("https://api.twitter.com/2") {
88+
Authenticator = new OAuth2ClientCredentialsAuthenticator(tokenRequest)
89+
};
90+
_client = new RestClient(opt);
8491
}
8592
```
8693

0 commit comments

Comments
 (0)