HTTPClient
public class HTTPClient
                HTTPClient class provides API for request execution.
Example:
    let client = HTTPClient(eventLoopGroupProvider: .createNew)
    client.get(url: "https://swift.org", deadline: .now() + .seconds(1)).whenComplete { result in
        switch result {
        case .failure(let error):
            // process error
        case .success(let response):
            if let response.status == .ok {
                // handle response
            } else {
                // handle remote error
            }
        }
    }
It is important to close the client instance, for example in a defer statement, after use to cleanly shutdown the underlying NIO EventLoopGroup:
    try client.syncShutdown()
              
          - 
                  
                  
Undocumented
Declaration
Swift
public let eventLoopGroup: EventLoopGroup - 
                  
                  
Create an
HTTPClientwith specifiedEventLoopGroupprovider and configuration.Declaration
Swift
public convenience init(eventLoopGroupProvider: EventLoopGroupProvider, configuration: Configuration = Configuration())Parameters
eventLoopGroupProviderSpecify how
EventLoopGroupwill be created.configurationClient configuration.
 - 
                  
                  
Create an
HTTPClientwith specifiedEventLoopGroupprovider and configuration.Declaration
Swift
public required init(eventLoopGroupProvider: EventLoopGroupProvider, configuration: Configuration = Configuration(), backgroundActivityLogger: Logger)Parameters
eventLoopGroupProviderSpecify how
EventLoopGroupwill be created.configurationClient configuration.
 - 
                  
                  
Shuts down the client and
EventLoopGroupif it was created by the client.Declaration
Swift
public func syncShutdown() throws - 
                  
                  
Shuts down the client and event loop gracefully. This function is clearly an outlier in that it uses a completion callback instead of an EventLoopFuture. The reason for that is that NIO’s EventLoopFutures will call back on an event loop. The virtue of this function is to shut the event loop down. To work around that we call back on a DispatchQueue instead.
Declaration
Swift
public func shutdown(queue: DispatchQueue = .global(), _ callback: @escaping (Error?) -> Void) - 
                  
                  
Execute
GETrequest using specified URL.Declaration
Swift
public func get(url: String, deadline: NIODeadline? = nil) -> EventLoopFuture<Response>Parameters
urlRemote URL.
deadlinePoint in time by which the request must complete.
 - 
                  
                  
Execute
GETrequest using specified URL.Declaration
Swift
public func get(url: String, deadline: NIODeadline? = nil, logger: Logger) -> EventLoopFuture<Response>Parameters
urlRemote URL.
deadlinePoint in time by which the request must complete.
loggerThe logger to use for this request.
 - 
                  
                  
Execute
POSTrequest using specified URL.Declaration
Parameters
urlRemote URL.
bodyRequest body.
deadlinePoint in time by which the request must complete.
 - 
                  
                  
Execute
POSTrequest using specified URL.Declaration
Parameters
urlRemote URL.
bodyRequest body.
deadlinePoint in time by which the request must complete.
loggerThe logger to use for this request.
 - 
                  
                  
Execute
PATCHrequest using specified URL.Declaration
Parameters
urlRemote URL.
bodyRequest body.
deadlinePoint in time by which the request must complete.
 - 
                  
                  
Execute
PATCHrequest using specified URL.Declaration
Parameters
urlRemote URL.
bodyRequest body.
deadlinePoint in time by which the request must complete.
loggerThe logger to use for this request.
 - 
                  
                  
Execute
PUTrequest using specified URL.Declaration
Parameters
urlRemote URL.
bodyRequest body.
deadlinePoint in time by which the request must complete.
 - 
                  
                  
Execute
PUTrequest using specified URL.Declaration
Parameters
urlRemote URL.
bodyRequest body.
deadlinePoint in time by which the request must complete.
loggerThe logger to use for this request.
 - 
                  
                  
Execute
DELETErequest using specified URL.Declaration
Swift
public func delete(url: String, deadline: NIODeadline? = nil) -> EventLoopFuture<Response>Parameters
urlRemote URL.
deadlineThe time when the request must have been completed by.
 - 
                  
                  
Execute
DELETErequest using specified URL.Declaration
Swift
public func delete(url: String, deadline: NIODeadline? = nil, logger: Logger) -> EventLoopFuture<Response>Parameters
urlRemote URL.
deadlineThe time when the request must have been completed by.
loggerThe logger to use for this request.
 - 
                  
                  
Execute arbitrary HTTP request using specified URL.
Declaration
Parameters
methodRequest method.
urlRequest url.
bodyRequest body.
deadlinePoint in time by which the request must complete.
loggerThe logger to use for this request.
 - 
                  
                  
Execute arbitrary HTTP+UNIX request to a unix domain socket path, using the specified URL as the request to send to the server.
Declaration
Parameters
methodRequest method.
socketPathThe path to the unix domain socket to connect to.
urlPathThe URL path and query that will be sent to the server.
bodyRequest body.
deadlinePoint in time by which the request must complete.
loggerThe logger to use for this request.
 - 
                  
                  
Execute arbitrary HTTPS+UNIX request to a unix domain socket path over TLS, using the specified URL as the request to send to the server.
Declaration
Parameters
methodRequest method.
secureSocketPathThe path to the unix domain socket to connect to.
urlPathThe URL path and query that will be sent to the server.
bodyRequest body.
deadlinePoint in time by which the request must complete.
loggerThe logger to use for this request.
 - 
                  
                  
Execute arbitrary HTTP request using specified URL.
Declaration
Parameters
requestHTTP request to execute.
deadlinePoint in time by which the request must complete.
 - 
                  
                  
Execute arbitrary HTTP request using specified URL.
Declaration
Parameters
requestHTTP request to execute.
deadlinePoint in time by which the request must complete.
loggerThe logger to use for this request.
 - 
                  
                  
Execute arbitrary HTTP request using specified URL.
Declaration
Swift
public func execute(request: Request, eventLoop: EventLoopPreference, deadline: NIODeadline? = nil) -> EventLoopFuture<Response>Parameters
requestHTTP request to execute.
eventLoopNIO Event Loop preference.
deadlinePoint in time by which the request must complete.
 - 
                  
                  
Execute arbitrary HTTP request and handle response processing using provided delegate.
Declaration
Swift
public func execute(request: Request, eventLoop eventLoopPreference: EventLoopPreference, deadline: NIODeadline? = nil, logger: Logger?) -> EventLoopFuture<Response>Parameters
requestHTTP request to execute.
eventLoopNIO Event Loop preference.
deadlinePoint in time by which the request must complete.
loggerThe logger to use for this request.
 - 
                  
                  
Execute arbitrary HTTP request and handle response processing using provided delegate.
Declaration
Swift
public func execute<Delegate: HTTPClientResponseDelegate>(request: Request, delegate: Delegate, deadline: NIODeadline? = nil) -> Task<Delegate.Response>Parameters
requestHTTP request to execute.
delegateDelegate to process response parts.
deadlinePoint in time by which the request must complete.
 - 
                  
                  
Execute arbitrary HTTP request and handle response processing using provided delegate.
Declaration
Swift
public func execute<Delegate: HTTPClientResponseDelegate>(request: Request, delegate: Delegate, deadline: NIODeadline? = nil, logger: Logger) -> Task<Delegate.Response>Parameters
requestHTTP request to execute.
delegateDelegate to process response parts.
deadlinePoint in time by which the request must complete.
loggerThe logger to use for this request.
 - 
                  
                  
Execute arbitrary HTTP request and handle response processing using provided delegate.
Declaration
Swift
public func execute<Delegate: HTTPClientResponseDelegate>(request: Request, delegate: Delegate, eventLoop eventLoopPreference: EventLoopPreference, deadline: NIODeadline? = nil) -> Task<Delegate.Response>Parameters
requestHTTP request to execute.
delegateDelegate to process response parts.
eventLoopNIO Event Loop preference.
deadlinePoint in time by which the request must complete.
loggerThe logger to use for this request.
 - 
                  
                  
Execute arbitrary HTTP request and handle response processing using provided delegate.
Declaration
Swift
public func execute<Delegate: HTTPClientResponseDelegate>(request: Request, delegate: Delegate, eventLoop eventLoopPreference: EventLoopPreference, deadline: NIODeadline? = nil, logger originalLogger: Logger?) -> Task<Delegate.Response>Parameters
requestHTTP request to execute.
delegateDelegate to process response parts.
eventLoopNIO Event Loop preference.
deadlinePoint in time by which the request must complete.
 - 
                  
                  
See moreHTTPClientconfiguration.Declaration
Swift
public struct Configuration - 
                  
                  
Specifies how
See moreEventLoopGroupwill be created and establishes lifecycle ownership.Declaration
Swift
public enum EventLoopGroupProvider - 
                  
                  
Specifies how the library will treat event loop passed by the user.
See moreDeclaration
Swift
public struct EventLoopPreferenceextension HTTPClient.EventLoopPreference: CustomStringConvertible - 
                  
                  
Specifies decompression settings.
See moreDeclaration
Swift
public enum Decompression - 
                  
                  
A representation of an HTTP cookie.
See moreDeclaration
Swift
public struct Cookie - 
                  
                  
Represent HTTP response.
See moreDeclaration
Swift
public struct Response - 
                  
                  
Represent request body.
See moreDeclaration
Swift
public struct Body - 
                  
                  
Represent HTTP request.
See moreDeclaration
Swift
public struct Request - 
                  
                  
HTTP authentication
See moreDeclaration
Swift
public struct Authorization : Hashable 
            View on GitHub
          
            Install in Dash
          
      HTTPClient Class Reference