rootstrap / ios-base

Boilerplate for new iOS projects using Swift 5. Provides a handful of functionalities.
https://rootstrap.com/
MIT License
264 stars 63 forks source link

Send "Content-Type: application/json" in every request #30

Closed MaicolBen closed 7 years ago

MaicolBen commented 7 years ago

Now it will be needed after https://github.com/toptier/rails5_api_base/pull/46 is merged

mjurfest commented 7 years ago

Add: JSONEncoding.default in Alamofire.request(requestUrl, method: method, parameters: params, encoding: JSONEncoding.default, headers: header)

Replace fileprivate class func getHeader() -> [String: String]?:

fileprivate class func getHeader() -> [String: String]? {
    if let session = SessionDataManager.getSessionObject() {
      return [
        HTTPHeader.uid.rawValue: session.uid ?? "",
        HTTPHeader.client.rawValue: session.client ?? "",
        HTTPHeader.token.rawValue: session.accessToken ?? "",
        "Accept": "application/json",
        "Content-Type": "application/json"
      ]
    }

    return ["Accept": "application/json",
            "Content-Type": "application/json"]
  }
glm4 commented 7 years ago

@mjurfest X-USER-TOKEN is no longer valid for the new rails 5 api-base. We should add only the

"Accept": "application/json",
"Content-Type": "application/json"

part to the current header implementation in the swift-base

mjurfest commented 7 years ago

Previous post edited