The markdown parsing is broken/disabled for release notes. Sorry about that, I'm chasing the source of a crash that's been bringing this website down for the last couple of days.
swift-http-types
1 week ago
## Overview
This release migrates a lot of the types to use the `swift-http-types` package by Apple. It brings breaking changes, so new major version.
## Mocking
There's a new `NetworkClientProtocol` type that you can schedule network requests on. To mock network requests, you can use `NetworkClientMock` from the new `HPNetworkMock` library.
Example usage:
```swift
networkClient.mockRequest(ofType: SomeRequest.self) { _ in
ReturnTypeOfRequest() // or throw an error
}
// To remove all mocks
networkClient.removeAllMocks()
```
You can also specify whether `NetworkClientMock` should just fall-back to regular networking if there are no mocks configured for the request it's about the execute by using `fallbackToURLSessionIfNoMatchingMock`
If you need to go deeper, for example if you don't want to migrate to `NetworkClient`, you can use `URLSessionMock` to use with `URLSession`
Example usage of `URLSessionMock`:
```swift
lazy var mockedURLSession: URLSession = {
let configuration = URLSessionConfiguration.ephemeral
configuration.protocolClasses = [URLSessionMock.self]
return URLSession(configuration: configuration)
}()
// ...
_ = URLSessionMock.mockRequest(to: url, ignoresQuery: false) { _ in
let response = HTTPURLResponse(
url: url,
statusCode: 200,
httpVersion: nil,
headerFields: ["Content-Type": ContentType.applicationJSON.rawValue]
)!
return (someDataYouWant, response)
}
```
**Full Changelog**: https://github.com/henrik-dmg/HPNetwork/compare/3.1.2...4.0.0
Throwing URL Construction
3 years ago
This release is not really a v2 release, but it brings breaking changes. The `url: URL?` property on `NetworkRequest` has been removed and replaced by `makeURL() throws -> URL`
Synchronous requests and more
3 years ago
This release brings a couple new features and changes:
- you can schedule requests synchronously by calling `scheduleSynchronously(...` on a `Network` instance or directly on your request instance. This will return the result of the request directly instead of a `NetworkTask`
- the order of arguments for `URLBuilder` query items has been changed to match that of `URLQueryItem`
- you can now opt out of the JSON injection for `DecodableRequest` by providing `injectJSONOnError: Bool`
Some QOL improvements
3 years ago
Not much new in this one, here's an overview:
- `musicUserToken` is not an authentication method anymore but rather a static property of `NetworkRequestHeaderField` (`.musicUserToken(userToken)`)
- the method `urlRequest() -> URLRequest` on `NetworkRequest` is now private (this wasn't meant to be configurable anyways)
- you can now schedule a request directly by passing a `Network` instance to it, like this for example:
```swift
// ...
request.schedule { result in
// Handle result
}
```
Ability to supply custom URLSession
3 years ago
You are now required to supply a `URLSession` object to any type that conforms to `NetworkRequest` - the built in `DecodableRequest` and `ImageDownloadRequest` already support this in their initialiser
Support for specifying finishing queue
3 years ago