Request
Represents an HTTP request.
struct Request
Represents an HTTP request.
struct Request
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 Response
Represents an HTTP response.
final class Task<Response>
Response execution context.
init(url: URL, method: HTTPMethod = .GET, headers: HTTPHeaders = HTTPHeaders(), body: Body? = nil) throws
Create an HTTP Request
.
init(url: String, method: HTTPMethod = .GET, headers: HTTPHeaders = HTTPHeaders(), body: Body? = nil) throws
Create HTTP request.
init(url: URL, method: HTTPMethod = .GET, headers: HTTPHeaders = HTTPHeaders(), body: Body? = nil, tlsConfiguration: TLSConfiguration?) throws
Create an HTTP Request
.
init(url: String, method: HTTPMethod = .GET, headers: HTTPHeaders = HTTPHeaders(), body: Body? = nil, tlsConfiguration: TLSConfiguration?) throws
Create HTTP request.
var body: Body?
Request body, defaults to no body.
var headers: HTTPHeaders
Request custom HTTP Headers, defaults to no headers.
var host: String { get }
Remote host, resolved from URL
.
let method: HTTPMethod
Request HTTP method, defaults to GET
.
var port: Int { get }
Resolved port.
var scheme: String { get }
Remote HTTP scheme, resolved from URL
.
var tlsConfiguration: TLSConfiguration?
Request-specific TLS configuration, defaults to no request-specific TLS configuration.
let url: URL
Remote URL.
var useTLS: Bool { get }
Whether request will be executed using secure socket.
mutating func setBasicAuth(username: String, password: String)
Set basic auth for a request.