Skip to content

Swift library to handle HTTP Request and convert object using Codable

License

Notifications You must be signed in to change notification settings

josmanperez/NBApollo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NBApollo

NBApollo: A wrapper library around Alamofire HTTP Network with codable objects.

If you want to use it with Swift 4 then move to tag 0.1.7

Features

  • HTTP Response Validation
  • HTTP Request / Response Methods
  • JSON Codable compatible objects to return

Component Libraries

NBApollo use Alamofire to make request.

Requirements

  • iOS 10.0+
  • Xcode 11+
  • Swift 5+

Installation

CocoaPods

NBApollo is not on cocoapods yet, but you could install using Pod.

  pod 'NBApollo', :git => 'https://github.com/josmanperez/NBApollo.git', :tag => '0.2.0'

Usage

If you API returns a object, something like this:

{
 "id":"1234",
 "valid": true
}

Then you need to create a Codable object like this:

class Data: Decodable {
    
    enum CodingKeys: String, CodingKey {
        case id
        case valid
    }
    
    var id: String
    var valid: Bool
}

When you need to call your api to gather a JSON object (conforms Codable), just need to call

let apiRequest: ApiRestClient<Data> = {
    let api = ApiRestClient<Data>(urlServer: "api endpoint")
    return api
}()

When you need to call this method:

self.nodoRequest.request(with: headers, method: .get, parameters: nil) { 
	result in 

    case .failure(let error):
        ...

    case .success(let response):
        print(response)
}

License

NBApollo is released under the MIT license.