Skip to content

Commit

Permalink
[feat] APIService Get 추가 (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
BAEKYUJEONG committed Aug 30, 2024
1 parent e7c7ddc commit 0eedc9f
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions PLUV/Network/APIService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,29 @@ struct APIService {
static var shared = APIService()
var loginAccessTokenKey = "loginAccessTokenKey"

func get<T: Codable>(of type: T.Type, url: URLConvertible, success: @escaping (T) -> (), failure: ((Error) -> ())? = nil) {

let headers: HTTPHeaders = ["Content-Type":"application/json", "Accept":"application/json"]

AF.request(url,
method: .get,
encoding: JSONEncoding(options: []),
headers: headers)
.responseDecodable(of: type) { response in

switch response.result {
case .success(let value):
success(value)
case .failure(let error):
if let failure = failure {
failure(error)
} else {
AlertController(message: error.localizedDescription).show()
}
}
}
}

func post<T: Codable>(of type: T.Type, url: URLConvertible, parameters: [String : Any], success: @escaping (T) -> (), failure: ((Error) -> ())? = nil) {

let headers: HTTPHeaders = ["Content-Type":"application/json", "Accept":"application/json"]
Expand Down

0 comments on commit 0eedc9f

Please sign in to comment.