Skip to content

Instantly share code, notes, and snippets.

@popochess
Created May 3, 2017 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save popochess/ef0299ba60a67ae03bef4a24182ace69 to your computer and use it in GitHub Desktop.
Save popochess/ef0299ba60a67ae03bef4a24182ace69 to your computer and use it in GitHub Desktop.
//
// ApiManager.swift
//
// Created by ben
// Copyright © 2017年 popochess. All rights reserved.
//
import UIKit
import Alamofire
public class ApiManager: NSObject,URLSessionDelegate {
let defaultSessionConfig :URLSessionConfiguration = URLSessionConfiguration.default
static func request(
endpoint: Endpoint.Api,
completionHandler: @escaping (DataResponse<Any>) -> Void)
-> Request
{
let headers = [
"Content-Type": "application/json",
"Accept": "application/json"
]
print("path:\(endpoint.path)")
let request = Alamofire.request(
endpoint.path,
method: endpoint.method,
parameters: endpoint.parameters,
encoding: URLEncoding.default,
headers: headers
).responseJSON { (response) -> Void in
switch response.result {
case Result.success(let value):
print(value)
break
case Result.failure(let encodingError):
print(encodingError)
if let resCode = response.response?.statusCode {
print(resCode)
}
break
}
completionHandler(response)
}
return request
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment