Skip to content

Commit 083e3ee

Browse files
authored
Merge pull request #1 from BenShutt/feature/request-body
feature/request-body
2 parents 2073a71 + 21caada commit 083e3ee

24 files changed

Lines changed: 580 additions & 255 deletions

.github/workflows/swift.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# This workflow will build a Swift project
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-swift
3+
4+
name: Swift
5+
on:
6+
push:
7+
branches: ["main"]
8+
pull_request:
9+
branches: ["*"]
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest # For docker container
13+
container: swift:latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
- name: Build
17+
run: swift build -v --configuration release
18+
- name: Test
19+
run: swift test -v --configuration release

.swiftlint.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
excluded:
2+
- .build
3+
analyzer_rules:
4+
- unused_declaration
5+
- unused_import
6+
opt_in_rules:
7+
- all
8+
disabled_rules:
9+
- anonymous_argument_in_multiline_closure
10+
- balanced_xctest_lifecycle
11+
- conditional_returns_on_newline
12+
- contrasted_opening_brace
13+
- explicit_acl
14+
- explicit_enum_raw_value
15+
- explicit_top_level_acl
16+
- explicit_type_interface
17+
- file_header
18+
- inert_defer # Deprecated
19+
- missing_docs
20+
- no_extension_access_modifier
21+
- no_grouping_extension
22+
- one_declaration_per_file
23+
- prefer_nimble
24+
- required_deinit
25+
- sorted_enum_cases
26+
- switch_case_on_newline
27+
- trailing_closure
28+
- unused_capture_list # Deprecated
29+
- vertical_whitespace_between_cases
30+
attributes:
31+
attributes_with_arguments_always_on_line_above: true
32+
always_on_line_above:
33+
- "@MainActor"
34+
- "@Option"
35+
- "@Suite"
36+
always_on_same_line:
37+
- "@ViewBuilder"
38+
- "@Environment"
39+
- "@EnvironmentObject"
40+
- "@Test"
41+
closure_body_length:
42+
warning: 10
43+
error: 20
44+
function_body_length: 40
45+
large_tuple: 3
46+
number_separator:
47+
minimum_length: 5
48+
type_body_length: 300
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "1610"
4+
version = "1.7">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES"
8+
buildArchitectures = "Automatic">
9+
<BuildActionEntries>
10+
<BuildActionEntry
11+
buildForTesting = "YES"
12+
buildForRunning = "YES"
13+
buildForProfiling = "YES"
14+
buildForArchiving = "YES"
15+
buildForAnalyzing = "YES">
16+
<BuildableReference
17+
BuildableIdentifier = "primary"
18+
BlueprintIdentifier = "DataRequest"
19+
BuildableName = "DataRequest"
20+
BlueprintName = "DataRequest"
21+
ReferencedContainer = "container:">
22+
</BuildableReference>
23+
</BuildActionEntry>
24+
</BuildActionEntries>
25+
</BuildAction>
26+
<TestAction
27+
buildConfiguration = "Debug"
28+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
29+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
30+
shouldUseLaunchSchemeArgsEnv = "YES"
31+
shouldAutocreateTestPlan = "YES">
32+
<Testables>
33+
<TestableReference
34+
skipped = "NO">
35+
<BuildableReference
36+
BuildableIdentifier = "primary"
37+
BlueprintIdentifier = "DataRequestTests"
38+
BuildableName = "DataRequestTests"
39+
BlueprintName = "DataRequestTests"
40+
ReferencedContainer = "container:">
41+
</BuildableReference>
42+
</TestableReference>
43+
</Testables>
44+
</TestAction>
45+
<LaunchAction
46+
buildConfiguration = "Debug"
47+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
48+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
49+
launchStyle = "0"
50+
useCustomWorkingDirectory = "NO"
51+
ignoresPersistentStateOnLaunch = "NO"
52+
debugDocumentVersioning = "YES"
53+
debugServiceExtension = "internal"
54+
allowLocationSimulation = "YES">
55+
</LaunchAction>
56+
<ProfileAction
57+
buildConfiguration = "Release"
58+
shouldUseLaunchSchemeArgsEnv = "YES"
59+
savedToolIdentifier = ""
60+
useCustomWorkingDirectory = "NO"
61+
debugDocumentVersioning = "YES">
62+
<MacroExpansion>
63+
<BuildableReference
64+
BuildableIdentifier = "primary"
65+
BlueprintIdentifier = "DataRequest"
66+
BuildableName = "DataRequest"
67+
BlueprintName = "DataRequest"
68+
ReferencedContainer = "container:">
69+
</BuildableReference>
70+
</MacroExpansion>
71+
</ProfileAction>
72+
<AnalyzeAction
73+
buildConfiguration = "Debug">
74+
</AnalyzeAction>
75+
<ArchiveAction
76+
buildConfiguration = "Release"
77+
revealArchiveInOrganizer = "YES">
78+
</ArchiveAction>
79+
</Scheme>

Package.resolved

Lines changed: 13 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,73 @@
1-
// swift-tools-version: 5.9
1+
// swift-tools-version: 6.0
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription
55

6+
#if os(macOS)
7+
let dependencies: [Dependency] = [.alamofire, .swiftLint]
8+
let plugins: [Plugin] = [.swiftLint]
9+
#else
10+
let dependencies: [Dependency] = [.alamofire]
11+
let plugins: [Plugin] = []
12+
#endif
13+
14+
let name = "DataRequest"
615
let package = Package(
7-
name: "DataRequest",
16+
name: name,
817
platforms: [
918
.macOS(.v13),
1019
.iOS(.v16)
1120
],
1221
products: [
1322
.library(
14-
name: "DataRequest",
15-
targets: ["DataRequest"]
16-
)
17-
],
18-
dependencies: [
19-
.package(
20-
url: "https://github.com/Alamofire/Alamofire.git",
21-
.upToNextMajor(from: "5.8.0")
23+
name: name,
24+
targets: [name]
2225
)
2326
],
27+
dependencies: dependencies,
2428
targets: [
2529
.target(
26-
name: "DataRequest",
30+
name: name,
2731
dependencies: ["Alamofire"],
28-
path: "Sources"
32+
path: "Sources",
33+
plugins: plugins
2934
),
3035
.testTarget(
31-
name: "DataRequestTests",
32-
dependencies: ["DataRequest"],
33-
path: "Tests"
36+
name: "\(name)Tests",
37+
dependencies: [.byName(name: name)],
38+
path: "Tests",
39+
plugins: plugins
3440
)
3541
]
3642
)
43+
44+
// MARK: - Dependency
45+
46+
typealias Dependency = Package.Dependency
47+
extension Dependency {
48+
static var alamofire: Dependency {
49+
.package(
50+
url: "https://github.com/Alamofire/Alamofire.git",
51+
.upToNextMajor(from: "5.8.0")
52+
)
53+
}
54+
55+
static var swiftLint: Dependency {
56+
.package(
57+
url: "https://github.com/SimplyDanny/SwiftLintPlugins",
58+
.upToNextMajor(from: "0.0.0")
59+
)
60+
}
61+
}
62+
63+
// MARK: - Plugin
64+
65+
typealias Plugin = PackageDescription.Target.PluginUsage
66+
extension Plugin {
67+
static var swiftLint: Plugin {
68+
.plugin(
69+
name: "SwiftLintBuildToolPlugin",
70+
package: "SwiftLintPlugins"
71+
)
72+
}
73+
}

README.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
Modularization of data requests using Alamofire with concurrency.
44

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

1010
## Example Usage
1111

1212
Define a decodable model returned in a response:
1313

1414
```swift
15-
struct Model: Decodable { ... }
15+
struct Model: Decodable, Sendable { ... }
1616
```
1717

1818
Specify the configuration of the request endpoint:
@@ -21,9 +21,10 @@ Specify the configuration of the request endpoint:
2121
struct GetModel: DecodableRequest {
2222
typealias ResponseBody = Model
2323

24-
var urlComponents: URLComponents {
25-
...
26-
}
24+
var urlComponents: URLComponents { ... }
25+
var method: HTTPMethod { ... }
26+
var headers: HTTPHeaders { ... }
27+
var body: HTTPBody? { ... }
2728
}
2829
```
2930

@@ -46,13 +47,9 @@ dependencies: [
4647
]
4748
```
4849

49-
## Notes
50-
51-
* The `URLRequestMaker` checks for conformance of `RequestBody` and adds the HTTP body accordingly
52-
* A `DecodableRequest` is a `URLRequestMaker` with the configuration properties of a data request defaulted
53-
5450
## Uploads
5551

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

5855
```swift
@@ -78,3 +75,7 @@ extension Session {
7875
```
7976

8077
This can be returned in the `session` property of the `DecodableRequest`.
78+
79+
## GitHub Actions
80+
81+
The `.github/workflows/swift.yml` GitHub action checks that the Swift package builds and the tests past using a swift docker container.

Sources/Body/DataBody.swift

Lines changed: 0 additions & 23 deletions
This file was deleted.

Sources/Body/JSONBody.swift

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)