Task
Response execution context.
final class Task<Response>
Will be created by the library and could be used for obtaining EventLoopFuture<Response>
of the execution or cancellation of the execution.
Response execution context.
final class Task<Response>
Will be created by the library and could be used for obtaining EventLoopFuture<Response>
of the execution or cancellation of the execution.
import AsyncHTTPClient
This package provides simple HTTP Client library built on top of SwiftNIO.
class HTTPClient
HTTPClient class provides API for request execution.
convenience init(eventLoopGroup: EventLoopGroup = HTTPClient.defaultEventLoopGroup, configuration: Configuration = Configuration())
Create an HTTPClient
with specified EventLoopGroup
and configuration.
convenience init(eventLoopGroup: any EventLoopGroup = HTTPClient.defaultEventLoopGroup, configuration: Configuration = Configuration(), backgroundActivityLogger: Logger)
Create an HTTPClient
with specified EventLoopGroup
and configuration.
convenience init(eventLoopGroupProvider: EventLoopGroupProvider, configuration: Configuration = Configuration())
Create an HTTPClient
with specified EventLoopGroup
provider and configuration.
convenience init(eventLoopGroupProvider: EventLoopGroupProvider, configuration: Configuration = Configuration(), backgroundActivityLogger: Logger)
Create an HTTPClient
with specified EventLoopGroup
provider and configuration.
static var defaultEventLoopGroup: EventLoopGroup { get }
Returns the default EventLoopGroup
singleton, automatically selecting the best for the platform.
static var shared: HTTPClient { get }
A globally shared, singleton HTTPClient
.
static func withHTTPClient<Return>(eventLoopGroup: any EventLoopGroup = HTTPClient.defaultEventLoopGroup, configuration: Configuration = Configuration(), backgroundActivityLogger: Logger? = nil, isolation: isolated (any Actor)? = #isolation, _ body: (HTTPClient) async throws -> Return) async throws -> Return
Start & automatically shut down a new HTTPClient
.
let eventLoopGroup: EventLoopGroup
The EventLoopGroup
in use by this HTTPClient
.
func delete(url: String, deadline: NIODeadline? = nil) -> EventLoopFuture<Response>
Execute DELETE
request using specified URL.
func delete(url: String, deadline: NIODeadline? = nil, logger: Logger) -> EventLoopFuture<Response>
Execute DELETE
request using specified URL.
func execute(_ request: HTTPClientRequest, deadline: NIODeadline, logger: Logger? = nil) async throws -> HTTPClientResponse
Execute arbitrary HTTP requests.
func execute(_ method: HTTPMethod = .GET, secureSocketPath: String, urlPath: String, body: Body? = nil, deadline: NIODeadline? = nil, logger: Logger? = nil) -> EventLoopFuture<Response>
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.
func execute(_ method: HTTPMethod = .GET, socketPath: String, urlPath: String, body: Body? = nil, deadline: NIODeadline? = nil, logger: Logger? = nil) -> EventLoopFuture<Response>
Execute arbitrary HTTP+UNIX request to a unix domain socket path, using the specified URL as the request to send to the server.
func execute(_ request: HTTPClientRequest, timeout: TimeAmount, logger: Logger? = nil) async throws -> HTTPClientResponse
Execute arbitrary HTTP requests.
func execute(_ method: HTTPMethod = .GET, url: String, body: Body? = nil, deadline: NIODeadline? = nil, logger: Logger? = nil) -> EventLoopFuture<Response>
Execute arbitrary HTTP request using specified URL.
func execute(request: Request, deadline: NIODeadline? = nil) -> EventLoopFuture<Response>
Execute arbitrary HTTP request using specified URL.
func execute(request: Request, deadline: NIODeadline? = nil, logger: Logger) -> EventLoopFuture<Response>
Execute arbitrary HTTP request using specified URL.
func execute<Delegate>(request: Request, delegate: Delegate, deadline: NIODeadline? = nil) -> Task<Delegate.Response> where Delegate : HTTPClientResponseDelegate
Execute arbitrary HTTP request and handle response processing using provided delegate.
func execute<Delegate>(request: Request, delegate: Delegate, deadline: NIODeadline? = nil, logger: Logger) -> Task<Delegate.Response> where Delegate : HTTPClientResponseDelegate
Execute arbitrary HTTP request and handle response processing using provided delegate.
func execute<Delegate>(request: Request, delegate: Delegate, eventLoop eventLoopPreference: EventLoopPreference, deadline: NIODeadline? = nil) -> Task<Delegate.Response> where Delegate : HTTPClientResponseDelegate
Execute arbitrary HTTP request and handle response processing using provided delegate.
func execute<Delegate>(request: Request, delegate: Delegate, eventLoop eventLoopPreference: EventLoopPreference, deadline: NIODeadline? = nil, logger: Logger?) -> Task<Delegate.Response> where Delegate : HTTPClientResponseDelegate
Execute arbitrary HTTP request and handle response processing using provided delegate.
func execute(request: Request, eventLoop: EventLoopPreference, deadline: NIODeadline? = nil) -> EventLoopFuture<Response>
Execute arbitrary HTTP request using specified URL.
func execute(request: Request, eventLoop eventLoopPreference: EventLoopPreference, deadline: NIODeadline? = nil, logger: Logger?) -> EventLoopFuture<Response>
Execute arbitrary HTTP request and handle response processing using provided delegate.
func get(url: String, deadline: NIODeadline? = nil) -> EventLoopFuture<Response>
Execute GET
request using specified URL.
func get(url: String, deadline: NIODeadline? = nil, logger: Logger) -> EventLoopFuture<Response>
Execute GET
request using specified URL.
func patch(url: String, body: Body? = nil, deadline: NIODeadline? = nil) -> EventLoopFuture<Response>
Execute PATCH
request using specified URL.
func patch(url: String, body: Body? = nil, deadline: NIODeadline? = nil, logger: Logger) -> EventLoopFuture<Response>
Execute PATCH
request using specified URL.
func post(url: String, body: Body? = nil, deadline: NIODeadline? = nil) -> EventLoopFuture<Response>
Execute POST
request using specified URL.
func post(url: String, body: Body? = nil, deadline: NIODeadline? = nil, logger: Logger) -> EventLoopFuture<Response>
Execute POST
request using specified URL.
func put(url: String, body: Body? = nil, deadline: NIODeadline? = nil) -> EventLoopFuture<Response>
Execute PUT
request using specified URL.
func put(url: String, body: Body? = nil, deadline: NIODeadline? = nil, logger: Logger) -> EventLoopFuture<Response>
Execute PUT
request using specified URL.
func shutdown() -> EventLoopFuture<Void>
Shuts down the HTTPClient
and releases its resources.
func shutdown() async throws
Shuts down the client and EventLoopGroup
if it was created by the client.
@preconcurrency func shutdown(queue: DispatchQueue = .global(), _ callback: @escaping (Error?) -> Void)
Shuts down the client and event loop gracefully.
func syncShutdown() throws
Shuts down the client and EventLoopGroup
if it was created by the client.
struct Authorization
HTTP authentication.
struct Body
A request body.
struct Configuration
HTTPClient
configuration.
struct Cookie
A representation of an HTTP cookie.
enum Decompression
Specifies decompression settings.
enum EventLoopGroupProvider
Specifies how EventLoopGroup
will be created and establishes lifecycle ownership.
struct EventLoopPreference
Specifies how the library will treat the event loop passed by the user.
struct Request
Represents an HTTP request.
struct Response
Represents an HTTP response.
let eventLoop: EventLoop
The EventLoop
the delegate will be executed on.
var futureResult: EventLoopFuture<Response> { get }
EventLoopFuture
for the response returned by this request.
let logger: Logger
The Logger
used by the Task
for logging.
func cancel()
Initiate cancellation of a HTTP request.
func fail(reason error: Error)
Initiate cancellation of a HTTP request with an error
.
func get() async throws -> Response
Provides the result of this request.
func wait() throws -> Response
Waits for execution of this request to complete.
protocol Copyable
A type whose values can be implicitly or explicitly copied.
protocol Escapable
protocol Sendable