immobiliare/RealHTTP 是一个托管在 GitHub 上的开源项目,主要使用 Swift 编写,采用 MIT License 许可证,目前获得 294 个 Star、29 次 Fork。
仓库全名
immobiliare/RealHTTP
README 摘要
RealHTTP is a lightweight yet powerful async-based HTTP library made in Swift. This project aims to make an easy-to-use, effortless HTTP client based on all the best new Swift features. What will you get? Below is a simple HTTP call in RealHTTP. 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: The code…
RealHTTP is a lightweight yet powerful async-based HTTP library made in Swift.
This project aims to make an easy-to-use, effortless HTTP client based on all the best new Swift features.
What will you get?
Below 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:
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!
Feature Highlights
RealHTTP offers lots of features and customization you can find in our extensive documentation and test suite.
Some of them are:
Async/Await native support
Requests queue built-in
Based upon native URLSession technology
Advanced retry mechanisms
Chainable & customizable response validators like Node’s Express.js
RealHTTP is fully documented at source-code level. You’ll get autocomplete with doc inside XCode for free; moreover you can read the full Apple’s DoCC Documentation automatically generated thanks to Swift Package Index Project from here:
RealHTTP has an extensive unit test suite covering many standard and edge cases, including request build, parameter encoding, queuing, and retries strategies.
See the XCTest suite inside Tests/RealHTTPTests folder.
Requirements
RealHTTP can be installed on any platform which supports:
iOS 13+, macOS Catalina+, watchOS 6+, tvOS 13+
Xcode 13.2+
Swift 5.5+
Installation
Swift Package Manager
Add it as a dependency in a Swift Package, and add it to your Package. Swift:
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.
CocoaPods
RealHTTP can be installed with CocoaPods by adding pod ‘RealHTTP’ to your Podfile.
pod 'RealHTTP'
Powered Apps
The fantastic mobile team at ImmobiliareLabs created RealHTTP.
We are currently using RealHTTP in all of our products.
We’d love for you to contribute to RealHTTP!
If you have questions about using RealHTTP, bugs, and enhancement, please feel free to reach out by opening a GitHub Issue.
评论