RealHTTP is a lightweight yet powerful async/await based client-side HTTP library made in Swift.
The goal of this project is to make an easy to use, effortless http client based upon all the best new Swift features.
This is a simple http call in RealHTTP
let todo = try await HTTPRequest("https://jsonplaceholder.typicode.com/todos/1")
.fetch(Todo.self)
One line of code, including the automatic decode from JSON to object.
Of course you can fully configure the request with many other parameters, take a look here:
let req = HTTPRequest {
// Setup default params
$0.url = URL(string: "https://.../login")!
$0.method = .post
$0.timeout = 15
// Setup some additional settings
$0.redirectMode = redirect
$0.maxRetries = 4
$0.headers = HTTPHeaders([
.init(name: .userAgent, value: myAgent),
.init(name: "X-API-Experimental", value: "true")
])
// Setup URL query params & body
$0.addQueryParameter(name: "full", value: "1")
$0.addQueryParameter(name: "autosignout", value: "30")
$0.body = .json(["username": username, "pwd": pwd])
}
let _ = try await req.fetch()
This is fully type-safe too!
Integrated stubber is perfect to write your own test suite:
That's a simple stubber which return the original request as response:
let echoStub = HTTPStubRequest().match(urlRegex: "*").stubEcho()
HTTPStubber.shared.add(stub: echoStub)
HTTPStubber.shared.enable()
Of course you can fully configure your stub with rules (regex, URI template and more):
// This is a custom stubber for any post request.
var stub = HTTPStubRequest()
.stub(for: .post, { response in
response.responseDelay = 5
response.headers = HTTPHeaders([
.contentType: HTTPContentType.bmp.rawValue,
.contentLength: String(fileSize,
])
response.body = fileContent
})
HTTPStubber.shared.add(stub: stub)
That's all!
RealHTTP offers lots of features and customization you can found in our extensive documentation and test suite.
Some of them are:
And for pro users:
RealHTTP is provided with an extensive documentation.
RealHTTP has an extensive unit test suite which covers many of the standard and edge cases including request build, parameter encoding, queuing and retry strategies.
See the XCTest suite inside Tests/RealHTTPTests
folder.
RealHTTP can be installed in any platform which supports:
Aadd it as a dependency in a Swift Package, add it to your Package.swift:
dependencies: [
.package(url: "https://github.com/immobiliare/RealHTTP.git", from: "1.0.0")
]
And add it as a dependency of your target:
targets: [
.target(name: "MyTarget", dependencies: [
.product(name: "https://github.com/immobiliare/RealHTTP.git", package: "RealHTTP")
])
]
In Xcode 11+ you can also navigate to the File menu and choose Swift Packages -> Add Package Dependency..., then enter the repository URL and version details.
RealHTTP can be installed with CocoaPods by adding pod 'RealHTTP' to your Podfile.
pod 'RealHTTP'
RealHTTP was created by the amazing mobile team at ImmobiliareLabs, the Tech dept at Immobiliare.it, the first real estate site in Italy.
We are currently using RealHTTP in all of our products.
If you are using RealHTTP in your app drop us a message, we'll add below.
Made with ❤️ by ImmobiliareLabs & Contributors
We'd love for you to contribute to RealHTTP!
If you have any questions on how to use RealHTTP, bugs and enhancement please feel free to reach out by opening a GitHub Issue.
link |
Stars: 154 |
Last commit: 1 week ago |
HTTPResponse
as result of a validation inside the HTTPValidator
response using the nextValidatorWithResponse
action response.Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics