|
| 1 | +// |
| 2 | +// Direct.swift |
| 3 | +// |
| 4 | +// |
| 5 | +// Created by Igor on 11.03.2023. |
| 6 | +// |
| 7 | + |
| 8 | +import Foundation |
| 9 | +import retry_policy_service |
| 10 | + |
| 11 | +public extension Http{ |
| 12 | + |
| 13 | + struct Get{ |
| 14 | + public static func from( |
| 15 | + _ url : URL, |
| 16 | + query : Http.Query? = nil, |
| 17 | + headers : Http.Headers? = nil, |
| 18 | + retry : UInt = 1, |
| 19 | + taskDelegate: ITaskDelegate? = nil |
| 20 | + ) async throws -> (Data, URLResponse){ |
| 21 | + let request = try buildURLRequest(for: url, query: query, headers: headers) |
| 22 | + let strategy = RetryService.Strategy.exponential(retry: retry) |
| 23 | + |
| 24 | + return try await sendRetry(with: request, retry: strategy) |
| 25 | + } |
| 26 | + } |
| 27 | + |
| 28 | + struct Post{ |
| 29 | + public static func from( |
| 30 | + _ url : URL, |
| 31 | + query : Http.Query? = nil, |
| 32 | + body : Data? = nil, |
| 33 | + headers : Http.Headers? = nil, |
| 34 | + retry : UInt = 1, |
| 35 | + taskDelegate: ITaskDelegate? = nil |
| 36 | + ) async throws -> (Data, URLResponse){ |
| 37 | + let request = try buildURLRequest(for: url, method: .post, query: query, body: body, headers: headers) |
| 38 | + let strategy = RetryService.Strategy.exponential(retry: retry) |
| 39 | + |
| 40 | + return try await sendRetry(with: request, retry: strategy) |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + struct Put{ |
| 45 | + public static func from( |
| 46 | + _ url : URL, |
| 47 | + query : Http.Query? = nil, |
| 48 | + body : Data? = nil, |
| 49 | + headers : Http.Headers? = nil, |
| 50 | + retry : UInt = 1, |
| 51 | + taskDelegate: ITaskDelegate? = nil |
| 52 | + ) async throws -> (Data, URLResponse){ |
| 53 | + let request = try buildURLRequest(for: url, method: .put, query: query, body: body, headers: headers) |
| 54 | + let strategy = RetryService.Strategy.exponential(retry: retry) |
| 55 | + |
| 56 | + return try await sendRetry(with: request, retry: strategy) |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + struct Delete{ |
| 61 | + public static func from( |
| 62 | + _ url : URL, |
| 63 | + query : Http.Query? = nil, |
| 64 | + headers : Http.Headers? = nil, |
| 65 | + retry : UInt = 1, |
| 66 | + taskDelegate: ITaskDelegate? = nil |
| 67 | + ) async throws -> (Data, URLResponse){ |
| 68 | + let request = try buildURLRequest(for: url, method: .delete, query: query, headers: headers) |
| 69 | + let strategy = RetryService.Strategy.exponential(retry: retry) |
| 70 | + |
| 71 | + return try await sendRetry(with: request, retry: strategy) |
| 72 | + } |
| 73 | + } |
| 74 | +} |
0 commit comments