Update LCEssentials+API.swift
This commit is contained in:
@@ -26,7 +26,6 @@ import Foundation
|
|||||||
import Security
|
import Security
|
||||||
#endif
|
#endif
|
||||||
#if canImport(UIKit)
|
#if canImport(UIKit)
|
||||||
#if canImport(UIKit)
|
|
||||||
import UIKit
|
import UIKit
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
@@ -47,6 +46,8 @@ public enum httpMethod: String {
|
|||||||
case get = "GET"
|
case get = "GET"
|
||||||
/// The PUT method.
|
/// The PUT method.
|
||||||
case put = "PUT"
|
case put = "PUT"
|
||||||
|
/// The PATCH method.
|
||||||
|
case patch = "PATCH"
|
||||||
/// The DELETE method.
|
/// The DELETE method.
|
||||||
case delete = "DELETE"
|
case delete = "DELETE"
|
||||||
}
|
}
|
||||||
@@ -90,7 +91,7 @@ public struct API {
|
|||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
/// - url: The URL string for the request.
|
/// - url: The URL string for the request.
|
||||||
/// - params: Optional parameters for the request. Can be `[String: Any]` for JSON/form-data, or `Data` for raw body.
|
/// - params: Optional parameters for the request. Can be `[String: Any]` for JSON/form-data, or `Data` for raw body.
|
||||||
/// - method: The HTTP method to use for the request (`.get`, `.post`, `.put`, `.delete`).
|
/// - method: The HTTP method to use for the request (`.get`, `.post`, `.put`, `.delete`,`.patch` ).
|
||||||
/// - headers: Optional custom HTTP headers to be added to the request. These override default headers if there are conflicts.
|
/// - headers: Optional custom HTTP headers to be added to the request. These override default headers if there are conflicts.
|
||||||
/// - jsonEncoding: A boolean indicating whether parameters should be JSON encoded. Defaults to `true`.
|
/// - jsonEncoding: A boolean indicating whether parameters should be JSON encoded. Defaults to `true`.
|
||||||
/// - debug: A boolean indicating whether to print debug logs for the request and response. Defaults to `true`.
|
/// - debug: A boolean indicating whether to print debug logs for the request and response. Defaults to `true`.
|
||||||
@@ -110,8 +111,8 @@ public struct API {
|
|||||||
persistConnection: Bool = false) async throws -> T {
|
persistConnection: Bool = false) async throws -> T {
|
||||||
|
|
||||||
if let urlReq = URL(string: url.replaceURL(params as? [String: Any] ?? [:] )) {
|
if let urlReq = URL(string: url.replaceURL(params as? [String: Any] ?? [:] )) {
|
||||||
var request = URLRequest(url: urlReq, cachePolicy: .reloadIgnoringLocalCacheData, timeoutInterval: 30)
|
var request = URLRequest(url: urlReq, cachePolicy: .reloadIgnoringLocalCacheData, timeoutInterval: timeoutInterval)
|
||||||
if method == .post || method == .put || method == .delete {
|
if method == .post || method == .put || method == .delete || method == .patch {
|
||||||
if let params = params as? [String: Any],
|
if let params = params as? [String: Any],
|
||||||
let pathFile = params["file"] as? String,
|
let pathFile = params["file"] as? String,
|
||||||
let fileURL = URL(string: pathFile) {
|
let fileURL = URL(string: pathFile) {
|
||||||
|
|||||||
Reference in New Issue
Block a user