Skip to content

Commit 9a06a30

Browse files
committed
Add fluent extensions for timeout
1 parent 5a79452 commit 9a06a30

15 files changed

Lines changed: 147 additions & 14 deletions

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public class Post
131131
}
132132
```
133133

134-
The FluentHttpClient version expresses the same logic in fewer lines, with better readability and no loss of functionality. All configuration, sending, error handling, and deserialization happen in a single fluent chain.
134+
Because a fluent API improves developer experience by turning tedious, repetitive setup into a readable, chainable flow that matches how you actually think about building and sending an HTTP request, The FluentHttpClient version expresses the same logic in fewer lines, with better readability and no loss of functionality. All configuration, sending, error handling, and deserialization happen in a single fluent chain.
135135

136136
## Usage and Support
137137

docs/docs/conditional-configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 8
2+
sidebar_position: 9
33
title: Conditional Configuration
44
---
55

docs/docs/configure-timeout.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
sidebar_position: 8
3+
title: Configure Timeout
4+
---
5+
6+
# Configure Timeout
7+
8+
FluentHttpClient provides a set of extensions for applying **per-request** timeouts. These timeouts define how long the client will wait for the current request to complete before canceling it. Timeouts are implemented through cancellation, do not alter `HttpClient.Timeout`, and have no effect on other requests made with the same `HttpClient` instance.
9+
10+
## Usage
11+
12+
A timeout may be applied using either a number of seconds or a `TimeSpan`. The timeout must be a positive value. When set, the request will be canceled if the configured interval elapses before the response is received.
13+
14+
```csharp
15+
var response = await client
16+
.UsingBase()
17+
.WithRoute("/todos/1")
18+
.WithTimeout(5) // 5-second timeout
19+
.GetAsync();
20+
```
21+
22+
```csharp
23+
var response = await client
24+
.UsingBase()
25+
.WithRoute("/todos/1")
26+
.WithTimeout(TimeSpan.FromMilliseconds(750))
27+
.GetAsync();
28+
```
29+
30+
Timeouts link with any caller-provided `CancellationToken`; whichever triggers first will cancel the request.
31+
32+
## Behavior Notes
33+
34+
* The timeout applies only to the current request and does not affect any other requests sent using the same `HttpClient` instance.
35+
* The timeout value must be a positive duration; zero or negative values are not allowed and will result in an exception.
36+
* The timeout does not modify `HttpClient.Timeout` and is enforced solely through per-request cancellation.
37+
* The timeout works together with any caller-provided `CancellationToken`, and the request will be canceled when either the timeout expires or the token is triggered.
38+
39+
## Quick Reference
40+
41+
| Method | Purpose |
42+
| ----------------------- | ------------------------------------------------- |
43+
| `WithTimeout(int)` | Applies a per-request timeout using seconds. |
44+
| `WithTimeout(TimeSpan)` | Applies a per-request timeout using a `TimeSpan`. |

docs/docs/deserializing-json.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 12
2+
sidebar_position: 13
33
title: Deserializing JSON
44
---
55

docs/docs/deserializing-xml.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 13
2+
sidebar_position: 14
33
title: Deserializing XML
44
---
55

docs/docs/httprequestbuilder.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ The table below lists the key properties on `HttpRequestBuilder` and how they ar
104104
| `bool BufferRequestContent` | Forces the request content to be fully buffered in memory before sending. Intended only for compatibility edge cases where buffering is required. See [Configure Content](./configure-content.md). |
105105
| `HttpQueryParameterCollection QueryParameters` | Represents all query string values for the request. The route and base address must not contain query components; this collection is the single source of truth. See [Configure Query Parameters](./configure-query-parameters.md). |
106106
| `string? Route` | The relative or absolute request route originally provided to the builder; validated so it contains no query or fragment. This value can be read, but cannot be changed. |
107+
| `TimeSpan? Timeout` | A per-request timeout that limits how long the client waits for the request to complete before canceling it. See [Configure Timeout](./configure-timeout.md). |
107108
| `Version Version` | The HTTP protocol version applied to the outgoing request. Defaults to HTTP/1.1. See [Configure Version](./configure-version.md). |
108109
| `HttpVersionPolicy VersionPolicy`* | Controls how the requested HTTP version is interpreted and negotiated (e.g., upgrade, downgrade, or strict). Defaults to `RequestVersionOrLower`. See [Configure Version](./configure-version.md). |
109110

docs/docs/native-aot-support.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 14
2+
sidebar_position: 15
33
title: Native AOT Support
44
---
55

docs/docs/response-content.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 11
2+
sidebar_position: 12
33
title: Read Response Content
44
---
55

docs/docs/response-handlers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 10
2+
sidebar_position: 11
33
title: Response Handlers
44
---
55

docs/docs/sending-requests.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 9
2+
sidebar_position: 10
33
title: Sending Requests
44
---
55

0 commit comments

Comments
 (0)