Skip to content

Commit 2b2155e

Browse files
committed
Add more detail to the Overview section of the documentation landing page.
1 parent 8f55fc1 commit 2b2155e

File tree

6 files changed

+42
-8
lines changed

6 files changed

+42
-8
lines changed

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,23 @@ HTTP libraries like `Foundation` pass the response through to the caller without
1515

1616
The module works with any HTTP library that is compatible with Swift’s [standard HTTP request and response types](https://github.com/apple/swift-http-types). The module can be used on its own in code that directly uses an HTTP library, or the module can be used as a building block by higher-level networking libraries.
1717

18-
## Example Usage
18+
### Representing an HTTP Application Failure
19+
20+
After interpreting an HTTP response as a success or a failure, there needs to be a way to represent a failure. In Swift, failures are represented by a type that conforms to the `Error` protocol. Therefore, the module exposes an `HTTPApplicationError` type to represent a failure.
21+
22+
### Interpreting HTTP Responses
23+
24+
The module extends `HTTPResponse` with a `throwIfFailed` method that interprets the response as a success or failure. The method throws `HTTPApplicationError` if the response is interpreted as a failure.
25+
26+
Some HTTP servers add additional details about a failure to the response body. The `throwIfFailed` method allows for the response body to be deserialized and attached to the error so that the additional failure details can be accessed later.
27+
28+
### Retrying HTTP Requests
29+
30+
The module extends `HTTPRequest` to add conformance to [`RetryableRequest`](https://fumoboy007.github.io/swift-retry/documentation/retry/retryablerequest), which is a protocol from the [`swift-retry`](https://swiftpackageindex.com/fumoboy007/swift-retry) package that adds safe retry methods to the type. The safe retry methods enforce that the HTTP request is [idempotent](https://httpwg.org/specs/rfc9110.html#idempotent.methods).
31+
32+
The retry method implementations automatically choose a [`RecoveryAction`](https://fumoboy007.github.io/swift-retry/documentation/retry/recoveryaction) for `HTTPApplicationError` using HTTP-specific information including whether the failure is transient and the value of the [`Retry-After`](https://httpwg.org/specs/rfc9110.html#field.retry-after) header, if present.
33+
34+
## Example Usage With `URLSession`
1935

2036
```swift
2137
import Foundation
File renamed without changes.
File renamed without changes.
File renamed without changes.

Sources/HTTPErrorHandling/HTTPErrorHandling.docc/HTTPErrorHandling.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,29 @@ HTTP libraries like `Foundation` pass the response through to the caller without
1010

1111
The module works with any HTTP library that is compatible with Swift’s [standard HTTP request and response types](https://github.com/apple/swift-http-types). The module can be used on its own in code that directly uses an HTTP library, or the module can be used as a building block by higher-level networking libraries.
1212

13+
### Representing an HTTP Application Failure
14+
15+
After interpreting an HTTP response as a success or a failure, there needs to be a way to represent a failure. In Swift, failures are represented by a type that conforms to the `Error` protocol. Therefore, the module exposes an ``HTTPApplicationError`` type to represent a failure.
16+
17+
### Interpreting HTTP Responses
18+
19+
The module extends `HTTPResponse` with a ``HTTPTypes/HTTPResponse/throwIfFailed(successStatuses:transientFailureStatuses:)`` method that interprets the response as a success or failure. The method throws ``HTTPApplicationError`` if the response is interpreted as a failure.
20+
21+
Some HTTP servers add additional details about a failure to the response body. The ``HTTPTypes/HTTPResponse/throwIfFailed(successStatuses:transientFailureStatuses:makeResponseBody:)`` method allows for the response body to be deserialized and attached to the error so that the additional failure details can be accessed later.
22+
23+
### Retrying HTTP Requests
24+
25+
The module extends `HTTPRequest` to add conformance to [`RetryableRequest`](https://fumoboy007.github.io/swift-retry/documentation/retry/retryablerequest), which is a protocol from the [`swift-retry`](https://swiftpackageindex.com/fumoboy007/swift-retry) package that adds safe retry methods to the type. The safe retry methods enforce that the HTTP request is [idempotent](https://httpwg.org/specs/rfc9110.html#idempotent.methods).
26+
27+
The retry method implementations automatically choose a [`RecoveryAction`](https://fumoboy007.github.io/swift-retry/documentation/retry/recoveryaction) for ``HTTPApplicationError`` using HTTP-specific information including whether the failure is transient and the value of the [`Retry-After`](https://httpwg.org/specs/rfc9110.html#field.retry-after) header, if present.
28+
1329
## Topics
1430

1531
### Examples
1632

17-
- <doc:Interpreting-HTTP-Responses>
18-
- <doc:Retrying-HTTP-Requests>
19-
- <doc:Interoperability-With-Popular-HTTP-Libraries>
33+
- <doc:Examples-of-Interpreting-HTTP-Responses>
34+
- <doc:Examples-of-Retrying-HTTP-Requests>
35+
- <doc:Examples-of-Interoperability-With-Popular-HTTP-Libraries>
2036

2137
### Representing an HTTP Application Failure
2238

Sources/HTTPErrorHandling/Retry/HTTPRequest+RetryableRequest.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,19 @@ import Retry
2525

2626
/// Adds `RetryableRequest` conformance to `HTTPRequest`.
2727
///
28-
/// The `RetryableRequest` conformance adds safe retry methods to `HTTPRequest`.
28+
/// The [`RetryableRequest`](https://fumoboy007.github.io/swift-retry/documentation/retry/retryablerequest)
29+
/// conformance adds safe retry methods to `HTTPRequest`.
2930
///
3031
/// - Important: The retry methods accept a closure that attempts the request. The closure must interpret the response
3132
/// and throw ``HTTPApplicationError`` when the response represents a failure. Calling
3233
/// ``HTTPTypes/HTTPResponse/throwIfFailed(successStatuses:transientFailureStatuses:)``
3334
/// is a convenient way to do so.
3435
///
3536
/// The `recoverFromFailure` closure is not called when the failure is due to ``HTTPApplicationError``. The
36-
/// retry method implementations automatically choose a recovery action for ``HTTPApplicationError`` using
37-
/// HTTP-specific information including whether the error is transient and the value of the `Retry-After` header,
38-
/// if present.
37+
/// retry method implementations automatically choose a
38+
/// [`RecoveryAction`](https://fumoboy007.github.io/swift-retry/documentation/retry/recoveryaction)
39+
/// for ``HTTPApplicationError`` using HTTP-specific information including whether the failure is transient and the
40+
/// value of the [`Retry-After`](https://httpwg.org/specs/rfc9110.html#field.retry-after) header, if present.
3941
///
4042
/// - SeeAlso: [`Retry`](https://fumoboy007.github.io/swift-retry/documentation/retry/)
4143
extension HTTPRequest: RetryableRequest {

0 commit comments

Comments
 (0)