Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This workflow will build a Swift project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-swift

name: Swift
on:
push:
branches: ["main"]
pull_request:
branches: ["*"]
jobs:
build:
runs-on: ubuntu-latest # For docker container
container: swift:latest
steps:
- uses: actions/checkout@v4
- name: Build
run: swift build -v --configuration release
- name: Test
run: swift test -v --configuration release
48 changes: 48 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
excluded:
- .build
analyzer_rules:
- unused_declaration
- unused_import
opt_in_rules:
- all
disabled_rules:
- anonymous_argument_in_multiline_closure
- balanced_xctest_lifecycle
- conditional_returns_on_newline
- contrasted_opening_brace
- explicit_acl
- explicit_enum_raw_value
- explicit_top_level_acl
- explicit_type_interface
- file_header
- inert_defer # Deprecated
- missing_docs
- no_extension_access_modifier
- no_grouping_extension
- one_declaration_per_file
- prefer_nimble
- required_deinit
- sorted_enum_cases
- switch_case_on_newline
- trailing_closure
- unused_capture_list # Deprecated
- vertical_whitespace_between_cases
attributes:
attributes_with_arguments_always_on_line_above: true
always_on_line_above:
- "@MainActor"
- "@Option"
- "@Suite"
always_on_same_line:
- "@ViewBuilder"
- "@Environment"
- "@EnvironmentObject"
- "@Test"
closure_body_length:
warning: 10
error: 20
function_body_length: 40
large_tuple: 3
number_separator:
minimum_length: 5
type_body_length: 300
79 changes: 79 additions & 0 deletions .swiftpm/xcode/xcshareddata/xcschemes/DataRequest.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1610"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
buildArchitectures = "Automatic">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DataRequest"
BuildableName = "DataRequest"
BlueprintName = "DataRequest"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DataRequestTests"
BuildableName = "DataRequestTests"
BlueprintName = "DataRequestTests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DataRequest"
BuildableName = "DataRequest"
BlueprintName = "DataRequest"
ReferencedContainer = "container:">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
16 changes: 13 additions & 3 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 52 additions & 15 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,36 +1,73 @@
// swift-tools-version: 5.9
// swift-tools-version: 6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

#if os(macOS)
let dependencies: [Dependency] = [.alamofire, .swiftLint]
let plugins: [Plugin] = [.swiftLint]
#else
let dependencies: [Dependency] = [.alamofire]
let plugins: [Plugin] = []
#endif

let name = "DataRequest"
let package = Package(
name: "DataRequest",
name: name,
platforms: [
.macOS(.v13),
.iOS(.v16)
],
products: [
.library(
name: "DataRequest",
targets: ["DataRequest"]
)
],
dependencies: [
.package(
url: "https://github.com/Alamofire/Alamofire.git",
.upToNextMajor(from: "5.8.0")
name: name,
targets: [name]
)
],
dependencies: dependencies,
targets: [
.target(
name: "DataRequest",
name: name,
dependencies: ["Alamofire"],
path: "Sources"
path: "Sources",
plugins: plugins
),
.testTarget(
name: "DataRequestTests",
dependencies: ["DataRequest"],
path: "Tests"
name: "\(name)Tests",
dependencies: [.byName(name: name)],
path: "Tests",
plugins: plugins
)
]
)

// MARK: - Dependency

typealias Dependency = Package.Dependency
extension Dependency {
static var alamofire: Dependency {
.package(
url: "https://github.com/Alamofire/Alamofire.git",
.upToNextMajor(from: "5.8.0")
)
}

static var swiftLint: Dependency {
.package(
url: "https://github.com/SimplyDanny/SwiftLintPlugins",
.upToNextMajor(from: "0.0.0")
)
}
}

// MARK: - Plugin

typealias Plugin = PackageDescription.Target.PluginUsage
extension Plugin {
static var swiftLint: Plugin {
.plugin(
name: "SwiftLintBuildToolPlugin",
package: "SwiftLintPlugins"
)
}
}
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

Modularization of data requests using Alamofire with concurrency.

This package encourages a design pattern where the configuration of an endpoint is encapsulated into the properties of a structure.
This package encourages a design pattern where the _description_ of an endpoint is encapsulated into the properties of a structure.
A similar design to a SwiftUI `View`.
It adds rather than replaces; direct use of Alamofire (or vanilla `URLSession`) is still encouraged.
It adds rather than replaces; direct use of Alamofire (or `URLSession`) is still encouraged.
There is also some helpful shorthand.

## Example Usage

Define a decodable model returned in a response:

```swift
struct Model: Decodable { ... }
struct Model: Decodable, Sendable { ... }
```

Specify the configuration of the request endpoint:
Expand All @@ -21,9 +21,10 @@ Specify the configuration of the request endpoint:
struct GetModel: DecodableRequest {
typealias ResponseBody = Model

var urlComponents: URLComponents {
...
}
var urlComponents: URLComponents { ... }
var method: HTTPMethod { ... }
var headers: HTTPHeaders { ... }
var body: HTTPBody? { ... }
}
```

Expand All @@ -46,13 +47,9 @@ dependencies: [
]
```

## Notes

* The `URLRequestMaker` checks for conformance of `RequestBody` and adds the HTTP body accordingly
* A `DecodableRequest` is a `URLRequestMaker` with the configuration properties of a data request defaulted

## Uploads

A `DecodableRequest` is a `URLRequestMaker` with the configuration properties of a data request defaulted.
Since `URLRequestMaker` conforms to `URLRequestConvertible` you can use Alamofire directly:

```swift
Expand All @@ -78,3 +75,7 @@ extension Session {
```

This can be returned in the `session` property of the `DecodableRequest`.

## GitHub Actions

The `.github/workflows/swift.yml` GitHub action checks that the Swift package builds and the tests past using a swift docker container.
23 changes: 0 additions & 23 deletions Sources/Body/DataBody.swift

This file was deleted.

45 changes: 0 additions & 45 deletions Sources/Body/JSONBody.swift

This file was deleted.

Loading
Loading