Skip to content

Releases: carson-katri/swift-request

v1.4.0

18 May 14:52
6266d88
Compare
Choose a tag to compare

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: { ... })
  • buildEither support in RequestBuilder (#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) {}
}
  • multipart/form-data support (#43, #51)

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", "[email protected]")
  }
}
  • @Requested property wrapper and reimplementation of RequestView (#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
  • @Requested property 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

28 Jul 00:34
1b4493f
Compare
Choose a tag to compare

What's New

This update adds some great new things:

  1. #24 New update methods to allow a Request to 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()

Read More

  1. #27 New Timeout param
Timeout(60)
Timeout(60, for: .request)
Timeout(60, for: .resource)
  1. #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.

  1. 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:

  1. #34 Improved Combine support
  2. @Requested property wrapper for your SwiftUI code

v1.2.2

21 Jun 19:24
Compare
Choose a tag to compare

Improved error handling coverage

Xcode beta 4 fixes

20 Jul 13:43
8f6ad76
Compare
Choose a tag to compare

This release brings bug fixes for Xcode beta 4. Specifically, it includes #3 to conform to BindableObject.