Skip to content

Commit

Permalink
1.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
dankinsoid committed Mar 28, 2024
1 parent 0e900a0 commit f849f25
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ import PackageDescription
let package = Package(
name: "SomeProject",
dependencies: [
.package(url: "https://github.com/dankinsoid/swift-api-client.git", from: "1.1.2")
.package(url: "https://github.com/dankinsoid/swift-api-client.git", from: "1.1.3")
],
targets: [
.target(
Expand Down
5 changes: 5 additions & 0 deletions Sources/SwiftAPIClient/APIClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ public struct APIClient {
return try await operation(configs)
}

/// Modifies the client using the provided closure.
public func modifier(_ modifier: (Self) throws -> Self) rethrows -> Self {
try modifier(self)
}

private func createRequest() throws -> (HTTPRequest, Configs) {
var configs = Configs()
let client = Self.globalModifier(self)
Expand Down
15 changes: 15 additions & 0 deletions Sources/SwiftAPIClient/Modifiers/RequestModifiers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,21 @@ public extension APIClient {
func header(_ field: HTTPField.Name, _ value: String, removeCurrent: Bool = false) -> APIClient {
headers(HTTPField(name: field, value: value), removeCurrent: removeCurrent)
}

/// Adds or updates a specific HTTP header for the request.
/// - Parameters:
/// - field: The key of the header to add or update.
/// - value: The value for the header.
/// - update: A Boolean to determine whether to remove the current header if it exists. Default is `false`.
/// - Returns: An instance of `APIClient` with modified header.
@_disfavoredOverload
func header(_ field: HTTPField.Name, _ value: CustomStringConvertible?, removeCurrent: Bool = false) -> APIClient {
if let value {
return headers(HTTPField(name: field, value: value.description), removeCurrent: removeCurrent)
} else {
return self
}
}
}

// MARK: - Body modifiers
Expand Down

0 comments on commit f849f25

Please sign in to comment.