StubNetworkKit

0.6.0

Stub your network requests in Swift
417-72KI/StubNetworkKit

What's New

0.6.0

2026-11-02T02:20:27Z

Caution

Breaking Change

Support for CocoaPods has been removed. Integrate this library via Swift Package Manager instead.

Important

Now requires Swift 6.1+

What's Changed

  • Migrate test with swift-testing by @417-72KI in #42
  • Prepare for Swift 6 pt.3 by @417-72KI in #46
  • Fix Danger warnings by @417-72KI in #48
  • Conform StubCondition to Hashable by @417-72KI in #47
  • TestPlan by @417-72KI in #50
  • Pin dependencies by @renovate[bot] in #51
  • Revert "Pin dependencies" by @417-72KI in #52
  • Update 417-72KI/danger-swiftlint action to v6 by @renovate[bot] in #56
  • Update 417-72KI/danger-swiftlint action to v6.1 by @renovate[bot] in #58
  • Update actions/download-artifact action to v5 by @renovate[bot] in #59
  • Update actions/checkout action to v5 by @renovate[bot] in #60
  • Update actions/upload-artifact action to v5 by @renovate[bot] in #62
  • Update actions/download-artifact action to v6 by @renovate[bot] in #61
  • Replace xcresulttool by @417-72KI in #74
  • Update actions/checkout action to v6 by @renovate[bot] in #64
  • Update slidoapp/xcresulttool action to v3.1.1 by @renovate[bot] in #75
  • Update dependency 417-72KI/MultipartFormDataParser to from: "2.3.2" by @renovate[bot] in #63
  • Update actions/download-artifact action to v8 by @renovate[bot] in #71
  • Update actions/upload-artifact action to v6 by @renovate[bot] in #72
  • Xcode 26 support by @417-72KI in #76
  • Pin actions/cache action to 0057852 by @renovate[bot] in #70
  • Update 417-72KI/danger-swiftlint action to v6.3 by @renovate[bot] in #65
  • Update slidoapp/xcresulttool action to v3.1.2 by @renovate[bot] in #77
  • Update actions/upload-artifact action to v7 by @renovate[bot] in #73
  • Update actions/cache action to v5 by @renovate[bot] in #66
  • Update actions/checkout digest to df4cb1c by @renovate[bot] in #78
  • Update actions/checkout action to v7 by @renovate[bot] in #79
  • Update actions/cache digest to caa2961 by @renovate[bot] in #80
  • Update actions/cache action to v6 by @renovate[bot] in #81
  • Update actions/cache digest to 55cc834 by @renovate[bot] in #82
  • Update actions/checkout digest to 3d3c42e by @renovate[bot] in #83
  • Update 417-72KI/danger-swiftlint action to v6.4 by @renovate[bot] in #84
  • Update actions/upload-artifact digest to cf430e0 by @renovate[bot] in #86
  • Update actions/download-artifact digest to 9000827 by @renovate[bot] in #85
  • Update slidoapp/xcresulttool action to v3.2.0 by @renovate[bot] in #87
  • Replace workflow for Pull Requests by @417-72KI in #89
  • Drop CocoaPods support by @417-72KI in #88
  • Swift 6 compatible and drop Swift 5.x by @417-72KI in #90
  • Switch to Swift 6 mode by @417-72KI in #91
  • Swift 6.2 compatible by @417-72KI in #93

Full Changelog: 0.5.0...0.6.0

StubNetworkKit

CI GitHub release GitHub license

100% pure Swift library to stub network requests.

100% pure Swift means,

  • No more Objective-C API
  • Testable also in other than Apple platform (e.g. Linux)

Installation

Swift Package Manager(recommended)

.package(url: "https://github.com/417-72KI/StubNetworkKit.git", from: "0.6.0"),

Preparation

Pure Swift is not supporting method-swizzling, therefore you have to enable stub explicitly.

If you are using URLSession.shared only, you can call registerStubForSharedSession() to enable stubs.

Otherwise, you should inject URLSessionConfiguration instance that stub is registered.

Sample codes with using Alamofire or APIKit exist in Sample.

Example

Basic

stub(Scheme.is("https") && Host.is("foo") && Path.is("/bar"))
    .responseJson(["message": "Hello world!"])

Switch response with conditional branches in request.

stub(Scheme.is("https") && Host.is("foo") && Path.is("/bar")) { request in
    guard request.url?.query == "q=1" else {
        return .error(.unexpectedRequest($0))
    }
    return .json(["message": "Hello world!"])
}

Using Result builder

stub {
    Scheme.is("https")
    Host.is("foo")
    Path.is("/bar")
    Method.isGet()
}.responseJson(["message": "Hello world!"])

Switch response with conditional branches in request.

stub {
    Scheme.is("https")
    Host.is("foo")
    Path.is("/bar")
    Method.isGet()
} withResponse: { request in
    guard request.url?.query == "q=1" else {
        return .error(.unexpectedRequest($0))
    }
    return .json(["message": "Hello world!"])
}

stub(url: "foo://bar/baz", method: .get)
    .responseData(Data("Hello world!".utf8))

Function chain

stub()
    .scheme("https")
    .host("foo")
    .path("/bar")
    .method(.get)
    .responseJson(["message": "Hello world!"])

More examples

If you are looking for more examples, look at StubNetworkKitTests.

Description

  • Swift Tools 6.2.0
View More Packages from this Author

Dependencies

Last updated: Sun Nov 08 2026 05:13:49 GMT-1000 (Hawaii-Aleutian Standard Time)