HttpX is a Swift package that provides easy-to-use HTTP client APIs, closely modeled after the API of the Python package httpx.
HttpX is a feature-rich HTTP client that build on the top of URLSession
from the Swift Foundation framework but with a more user-friendly API. It offers both synchronous and asynchronous methods for sending HTTP requests with minimal code. Additionally, HttpX simplifies handling authentication, redirects, proxies, cookies, and other features in just a few lines of code.
The Swift Package Manager is a tool that manages the distribution of Swift code by automating the process of downloading, compiling, and linking dependencies through integration with the Swift build system.
If your project uses the Swift Package Manager, you can add HttpX to it by including the following code in the Package.swift
file located in your project's root folder.
dependencies: [
.package(url: ""),
]
You can now add dependencies to your target as shown below:
.target(
name: "SomeProjects",
dependencies: ["HttpX"],
)
import HttpX
let response = try get(url: URLType.string("https://www.example.org/"))
print(response)
// <Response [200 no error]>
print(response.data!)
// 1256 bytes
print(String(data: response.data!, encoding: .utf8)!)
// <!doctype html><html>...</html>
For more information, please refer to the [documentation].
- Well-established API
- Support for async/await
- Redirects and history
- Easy access to request and response headers, Cookies, and more
- Support for Swift Cookie Identifiers
- Easy Authentication, Basic, Digest, and OAuth
- Common Request body types, JSON, Form, and more
- Uploading files via multipart/form-data
- Streaming Responses
- Automatic decide DataTask, UploadTask, and DownloadTask
- pass the URLSessionConfiguration
- Proxy Support
- Common Response Content Types Decoding, JSON, HTML, and more
HttpX is inspired by the Python package httpx. We bring their easy-to-use API to Swift, making HttpX serves as an adapter to Swift Foundation's URLSession.
We Keep httpx's license in our github repository.
We welcome contributions to HttpX by opening a pull request on GitHub.
HttpX is released under the Apache License, Version 2.0.