Authorization
HTTP authentication.
struct Authorization
HTTP authentication.
struct Authorization
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 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.
final class Task<Response>
Response execution context.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable : Equatable
A type that can be hashed into a Hasher
to produce an integer hash value.
protocol Sendable
static func basic(credentials: String) -> HTTPClient.Authorization
HTTP basic auth.
static func basic(username: String, password: String) -> HTTPClient.Authorization
HTTP basic auth.
static func bearer(tokens: String) -> HTTPClient.Authorization
HTTP bearer auth
var headerValue: String { get }
The header string for this auth field.
static func != (lhs: Self, rhs: Self) -> Bool
Returns a Boolean value indicating whether two values are not equal.