Latest 0.1.3
Homepage https://github.com/3zcurdia/amaca
License MIT
Platforms ios 11.0
Authors

Build Status
CI Status
Version
License
Platform
Maintainability

Installation

Amaca is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'Amaca'

Setup

Even when Amaca is based in convention over configuration principle, there are few things to setup.

AmacaConfigurable Protocol

You must implement a structure or a class conforming the AmacaConfigurable protocol where
it will be defined the base url and the session for your connections, among with the authentication structure
if needed.

public protocol ServicesConfig {
  var session: URLSession { get }
  var baseURL: URL { get }
}

Example

struct ServicesConfig: AmacaConfigurable {
    let session: URLSession = URLSession.shared
    let baseUrl: URL = URL(string: "https://example.com/api")!
}

Usage

To initialize a service you must create an instance with the Codable you desire
to parse a config and the path where all the RESTFUL routes reside.

Method URI Pattern Action
GET /users index
POST /users create
GET /users/:id show
PUT /users/:id update
DELETE /users/:id destroy

Then for each method you can call the correspondent action

Example Unauthenticated

  let config = ServicesConfig()
  let service = CodableService<User>(config: config, path: "/users", auth: nil)

  service.index { response in
    // your code goes here
    switch response.status {
    case .success:
      print(response.data!.count)
    default:
      print(response.status)
      print(response)
    }
  }

Authentication

Amaca provides authentication structs for query and header:

  • QueryAuthentication
  • HeaderAuthentication

Example Authenticated

  let config = ServicesConfig()
  let auth = QueryAuthentication(method: .basicHeader, token: "secret-token-1234")
  let service = CodableService<User>(config: config, path: "users", auth: auth)

  service.index { response in
    // your code goes here
    switch response.status {
    case .success:
      print(response.data!.count)
    default:
      print(response.status)
      print(response)
    }
  }

Note: CodableService internally implements dataTask other methods from URLSession could be supported in the future.

Contribute to the project

To contribute, just follow the next steps:

  • Check out the latest master to make sure the feature hasn’t been implemented or the bug hasn’t been fixed yet
  • Check out the issue tracker to make sure someone already hasn’t requested it and/or contributed it
  • Fork the project
  • Start a feature/bugfix branch
  • Commit and push until you are happy with your contribution
  • It is desired to add some tests for it.
  • Make a Pull Request

License

Amaca is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "Amaca",
    "version": "0.1.3",
    "summary": "A restful network interface",
    "description": "Multipropuse Network iterface for RESTful services with Codable objects",
    "homepage": "https://github.com/3zcurdia/amaca",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Luis Ezcurdia": "[email protected]"
    },
    "source": {
        "git": "https://github.com/3zcurdia/Amaca.git",
        "tag": "0.1.3"
    },
    "swift_version": "4.2",
    "platforms": {
        "ios": "11.0"
    },
    "source_files": "Amaca/Classes/**/*"
}

Pin It on Pinterest

Share This