Skip to content

Releases: henrik-dmg/HPNetwork

swift-http-types

12 Apr 07:06
4.0.0
6e1266a
Compare
Choose a tag to compare

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:

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:

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: 3.1.2...4.0.0

Throwing URL Construction

24 Mar 09:34
Compare
Choose a tag to compare

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

11 Mar 14:58
Compare
Choose a tag to compare

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

21 Jan 10:08
Compare
Choose a tag to compare

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:
// ...
request.schedule { result in
    // Handle result
}

Ability to supply custom URLSession

29 Jun 12:57
Compare
Choose a tag to compare

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

15 Jun 10:05
Compare
Choose a tag to compare

0.2.0

13 Apr 22:38
Compare
Choose a tag to compare

0.1.2

13 Apr 21:14
Compare
Choose a tag to compare
0.1.2 Pre-release
Pre-release

0.0.8

07 Apr 14:19
Compare
Choose a tag to compare