Skip to content

Commit

Permalink
Response type
Browse files Browse the repository at this point in the history
  • Loading branch information
3lvis committed Jul 16, 2024
1 parent a669c3f commit b716a38
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/Networking/Networking+HTTPRequests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public extension Networking {
await cancelRequest(.data, requestType: .get, url: url)
}

func get<T: Decodable>(_ path: String) async -> Result<T, NetworkingError> {
func get<T: Decodable>(_ path: String, responseType: T.Type) async -> Result<T, NetworkingError> {
return await handle(.get, path: path, parameters: nil)
}

Expand Down
15 changes: 15 additions & 0 deletions Tests/NetworkingTests/GETTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import Foundation
import XCTest
@testable import Networking

struct Friend: Decodable {
let id: UUID
let title: String
}

class GETTests: XCTestCase {
let baseURL = "http://httpbin.org"

Expand Down Expand Up @@ -225,4 +230,14 @@ class GETTests: XCTestCase {
}
}

func testNewGET() async throws {
let networking = Networking(baseURL: baseURL)
let result = await networking.get("/get", responseType: Friend.self)
switch result {
case .success(let success):
print("worked")
case .failure(let failure):
print(failure.localizedDescription)
}
}
}

0 comments on commit b716a38

Please sign in to comment.