Skip to content

Commit

Permalink
Protocol and batching updates
Browse files Browse the repository at this point in the history
  • Loading branch information
atljeremy committed Sep 21, 2024
1 parent 4d640f5 commit 16e37d2
Show file tree
Hide file tree
Showing 12 changed files with 205 additions and 144 deletions.
6 changes: 2 additions & 4 deletions HTTPService.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
3F43766F1AD1A14100FFC40C /* HTTPServiceTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = HTTPServiceTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
3F4376751AD1A14100FFC40C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
3F43768B1AD1A19300FFC40C /* HTTPService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HTTPService.swift; sourceTree = "<group>"; };
3F64449C1B0A102200AD34A0 /* HTTPServiceTests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "HTTPServiceTests-Bridging-Header.h"; sourceTree = "<group>"; };
3F98C32F1B0AAD5600AC23D4 /* PullRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PullRequest.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -203,7 +202,6 @@
3F4376741AD1A14100FFC40C /* Supporting Files */ = {
isa = PBXGroup;
children = (
3F64449C1B0A102200AD34A0 /* HTTPServiceTests-Bridging-Header.h */,
3F4376751AD1A14100FFC40C /* Info.plist */,
);
name = "Supporting Files";
Expand Down Expand Up @@ -560,7 +558,7 @@
);
PRODUCT_BUNDLE_IDENTIFIER = "com.jeremyfox.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "HTTPServiceTests/HTTPServiceTests-Bridging-Header.h";
SWIFT_OBJC_BRIDGING_HEADER = "";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
};
Expand All @@ -580,7 +578,7 @@
);
PRODUCT_BUNDLE_IDENTIFIER = "com.jeremyfox.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "HTTPServiceTests/HTTPServiceTests-Bridging-Header.h";
SWIFT_OBJC_BRIDGING_HEADER = "";
SWIFT_VERSION = 5.0;
};
name = Release;
Expand Down
44 changes: 43 additions & 1 deletion HTTPService/HTTPRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,48 @@ public protocol HTTPRequest {
init(id: String?)
}

public protocol HTTPBatchRequest {
associatedtype Request: HTTPRequest

var requests: [Request] { get }

init(requests: [Request])
}

struct Req: HTTPRequest {
typealias ResultType = String

typealias BodyType = HTTPRequestNoBody

var endpoint: String = ""

var method: HTTPMethod = .get

var params: [String : Any]? = nil

var body: HTTPRequestNoBody? = nil

var headers: [String : String]? = nil

var includeServiceLevelHeaders: Bool = true

var includeServiceLevelAuthorization: Bool = true

init(id: String?) {

}
}

struct BatchReq: HTTPBatchRequest {
typealias Request = Req

var requests: [Req]

init(requests: [Req]) {
self.requests = requests
}
}

/// Represents a response with no content, typically used for HTTP 204 (No Content) responses.
public struct HTTPResponseNoContent: Decodable {}

Expand Down Expand Up @@ -174,7 +216,7 @@ extension HTTPRequest {
request.addValue(auth.value, forHTTPHeaderField: "Authorization")
}

// Add the additional HTTP Headers passed in (most likely from the HTTPService)
// Add the additional HTTP Headers passed in (most likely from the NetworkService)
if includeServiceLevelHeaders {
// Add the service level headers
additionalHeaders?.forEach { (key, value) in
Expand Down
Loading

0 comments on commit 16e37d2

Please sign in to comment.