Skip to content

Commit eda51ac

Browse files
ianpartridgeartemredkin
authored andcommitted
feat: Add HTTPClient.patch() for sending PATCH requests (swift-server#15)
`PATCH` is a commonly supported verb in RESTful APIs. Although it is already possible to send a PATCH request via the `HTTPClient.execute()` API this commit adds an explicit `patch()` API for consistency. This gives us explicit APIs for `GET`, `POST`, `PUT`, `PATCH` and `DELETE`.
1 parent 15ee7ee commit eda51ac

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Diff for: Sources/NIOHTTPClient/SwiftNIOHTTP.swift

+9
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ public class HTTPClient {
8282
}
8383
}
8484

85+
public func patch(url: String, body: Body? = nil, timeout: Timeout? = nil) -> EventLoopFuture<Response> {
86+
do {
87+
let request = try HTTPClient.Request(url: url, method: .PATCH, body: body)
88+
return self.execute(request: request)
89+
} catch {
90+
return self.group.next().makeFailedFuture(error)
91+
}
92+
}
93+
8594
public func put(url: String, body: Body? = nil, timeout: Timeout? = nil) -> EventLoopFuture<Response> {
8695
do {
8796
let request = try HTTPClient.Request(url: url, method: .PUT, body: body)

0 commit comments

Comments
 (0)