Skip to content

Commit a823e22

Browse files
authored
Update README.md
1 parent dd3e5a9 commit a823e22

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

README.md

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Bifrost is available via Swift Package Manager.
88

99
```swift
1010
dependencies: [
11-
.package(url: "https://github.com/mtzaquia/bifrost.git", .upToNextMajor(from: "1.0.0")),
11+
.package(url: "https://github.com/mtzaquia/bifrost.git", from: "2.0.0"),
1212
],
1313
```
1414

@@ -30,9 +30,9 @@ You can define default parameters and headers that will apply to all requests. Y
3030
```swift
3131
struct MyAPI: API {
3232
// ...
33-
func defaultParameters() -> [String : Any] {
33+
func queryParameters() -> [URLQueryItem]
3434
[
35-
"api-key": "<my secret key>"
35+
URLQueryItem(name: "api-key", value: "<my secret key>")
3636
]
3737
}
3838

@@ -53,23 +53,18 @@ You can also provide default header fields for a specific request if needed, and
5353
struct MyRequest {
5454
private(set) var name: String
5555
private(set) var anotherParam: String?
56-
57-
enum CodingKeys: String, CodingKey {
58-
case name
59-
case anotherParam = "another-param"
60-
}
6156
}
6257

6358
extension MyRequest: Requestable {
64-
var path: String { "my-request.json" }
59+
var path: String { "api/my-request" }
6560

6661
struct Response: Decodable {
6762
let results: [MyResultObject]
6863
}
6964
}
7065
```
7166

72-
> **Note**
67+
> [!NOTE]
7368
> If you expect an empty response, the built-in `EmptyResponse` type is avaiable for convenience.
7469
7570
### Making the call
@@ -82,27 +77,30 @@ let response = try await MyAPI.response(for: MyRequest(name: "My fancy name"))
8277
print(response.results) // Our response is already a Swift type! More specifically, an instance of `MyRequest.Response`.
8378
```
8479

85-
### Mocking
80+
### Mocking, recovering
8681

87-
You may provide your own implementation of the `response(for:callback:)` function for mocking purposes:
82+
You may provide your own implementation of the `response(for:)` function for mocking purposes, or to handle recovery with custom logic:
8883

8984
```swift
9085
struct MockedAPI: API {
9186
let baseURL: URL = URL(string: "foo://bar")!
92-
87+
9388
func response<Request>(
94-
for request: Request,
95-
additionalHeaderFields: [String: String],
96-
callback: @escaping (Result<Request.Response, Error>) -> Void
97-
) where Request : Requestable {
98-
// my mocked implementation...
89+
for request: Request
90+
) async throws -> Request.Response where Request : Requestable {
91+
do {
92+
return try await _response(for: request)
93+
} catch BifrostError.unsuccessfulStatusCode(404) {
94+
try await _response(for: TokenRefreshRequest())
95+
}
96+
return try await _response(for: request)
9997
}
10098
}
10199
```
102100

103101
## License
104102

105-
Copyright (c) 2021 @mtzaquia
103+
Copyright (c) 2025 @mtzaquia
106104

107105
Permission is hereby granted, free of charge, to any person obtaining a copy
108106
of this software and associated documentation files (the "Software"), to deal

0 commit comments

Comments
 (0)