Releases: carson-katri/swift-request
v1.4.0
What's New
- Improved Combine support (#34)
Request is now a Publisher. This lets you use Combine operators on your Request:
Request {
Url("https://jsonplaceholder.typicode.com/todos")
}
.map(\.data)
.decode([Todo].self, decoder: JSONDecoder())
.sink(receiveCompletion: { ... }, receiveValue: { ... })There are also properties for objectPublisher, stringPublisher, and jsonPublisher. Using AnyRequest, that previous example could be rewritten as:
AnyRequest<[Todo]> {
Url("https://jsonplaceholder.typicode.com/todos")
}
.objectPublisher
.sink(receiveCompletion: { ... }, receiveValue: { ... })buildEithersupport inRequestBuilder(#39)- Concatenate
Urls with+(#39) -Url("https://baseurl.com") + Url("/path") - Improved internals of Request (#42)
If you would like to add your own parameters to be used in a Request, you can simply implement the RequestParam protocol:
struct MyCustomParam: RequestParam {
func buildParam(_ request: inout URLRequest) {}
}You can also conform to SessionParam to modify the URLSessionConfiguration:
struct MyCustomSessionParam: SessionParam {
func buildConfiguration(_ configuration: URLSessionConfiguration) {}
}Use the Form parameter in your Request body to send form data. You can send Form.Data for file content, and key-value pairs with Form.Value.
Request {
Url("http://example.com/send")
Method(.post)
Form {
Form.Data(data, named: "image.txt", withType: .text)
Form.Value(key: "email", "test@example.com")
}
}@Requestedproperty wrapper and reimplementation ofRequestView(#46, iOS 14+, macOS 11+)
This allows a Request to be specified in a property wrapper, and it will automatically update your View's body when the Request finishes. The projectedValue contains the status of the Request as a RequestStatus enum:
struct TodoList: View {
@Requested private var allTodos = AnyRequest<[Todo]> {
Url("https://jsonplaceholder.typicode.com/todos")
}
var body: some View {
switch $allTodos {
case .loading: ProgressView()
case let .failure(error): Text(error.localizedDescription)
case let .success(todos):
List(todos) { todo in
Label(todo.title, systemImage: "checkmark.circle\(todo.completed ? ".fill" : "")")
}
}
}
}RequestView was reimplemented for iOS 14+ and macOS 11+ to provide more reliability. It also provides a new initializer that uses a RequestStatus enum in the body:
RequestView(AnyRequest<[Todo]> {
Url("https://jsonplaceholder.typicode.com/todos")
}) { result in
switch result {
case .loading: ProgressView()
case let .failure(error): Text(error.localizedDescription)
case let .success(todos):
List(todos) { todo in
Label(todo.title, systemImage: "checkmark.circle\(todo.completed ? ".fill" : "")")
}
}
}Merged PRs
- Check if filename contains "." before splitting it bug (#53) by @brennobemoura
- Added Form.Value to send key and value content in a form data (#51) by @brennobemoura
- Update MediaType.swift (#47) by @rain2540
@Requestedproperty wrapper and reimplementation of RequestView (#46) by @carson-katri- Support MultipartFormData (#43) by @brennobemoura
- Simplify RequestParam internal API (#42) by @brennobemoura
- Solves #36 #37 (#39) by @brennobemoura
- Improve Combine Support (#34) by @carson-katri
v1.3.0
What's New
This update adds some great new things:
- #24 New
updatemethods to allow aRequestto be called repeatedly (thanks to @ezraberch)
Request {
Url("https://jsonplaceholder.typicode.com/todo")
}
.update(every: 10)
.update(publisher: Timer.publish(every: 10, on: .main, in: .common).autoconnect())
.call()- #27 New
Timeoutparam
Timeout(60)
Timeout(60, for: .request)
Timeout(60, for: .resource)- #31 Improved
RequestError(thanks to @brennobemoura)
RequestError now conforms to the Error protocol, and more error types can be caught and handled by your code.
- Fix overlap with SwiftUI
associatedtype Body
When setting the request's Body in a SwiftUI View, use RequestBody instead. This will avoid conflicts with the View protocol.
Coming Soon
This release had a lot of great stuff packed in. Here's a few things you can look for in the next release, 1.4.0:
- #34 Improved Combine support
@Requestedproperty wrapper for your SwiftUI code
v1.2.2
Improved error handling coverage
Xcode beta 4 fixes
This release brings bug fixes for Xcode beta 4. Specifically, it includes #3 to conform to BindableObject.