Latest 0.2.0
Homepage https://github.com/ckalnasy/ApiSwift
License MIT
Platforms ios 8.0, requires ARC
Dependencies SwiftSerialize
Authors

CI Status
Version
License
Platform

Usage

import CoreLocation
import ApiSwift
import SwiftSerialize

let url = NSURL(string: "http://localhost:8000/Api.php")
let obj1 = TestClass(string: "Test str", number: 4.5, location: CLLocationCoordinate2D(latitude: 33.2, longitude: 44), array: [3, 5, 84, 23], map: ["key1": ["key2" : 82]], set: [3.3, 55.3, 32.1])
let obj2 = 4321
let params:[Any] = [obj1, obj2]
let additionalParams:[String: String] = [
  "id": "1234567890",
]

let request = NSMutableURLRequest(url: url!, className: "MyClass", functionName: "MyFunc", params: params, additionalParams: additionalParams)
NSURLSession.sharedSession().dataTaskWithRequest(request) { (data, response, error) -> Void in
  // handle response
  let object = Serializer.deserialize(data!)
}.resume()

This example calls the MyFunc static function on the MyClass class. The 2 parameters are of type TestClass and an integer.
Traditional HTTP parameters can also be added to the request in the additionalParams.

How it works

The objects passed as params are serialzed into JSON before being sent to the server. The server will deserialze the objects and recreate the
objects on the server. Then, the static class function specified is called with the deserialzed objects.

This library uses SwiftSerialize to serialize objects. It can also deserialize objects to classes (custom classes you make or built-in Swift classes) with virtually no work on your end. Head over there to find out how to fully utilize this library.

Limitations

Currently the only server-side language that can handle this request is PHP.

Running the Example

To run the example project, clone the repo, and run pod install from the Example directory first.

You’ll also need to uncomment the commented lines in SwiftSerialize/Initializer.swift (in the SwiftSerialize pod) to run the test cases.

Installation

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

pod "ApiSwift"

Contributing

Will accept all valid pull requests, feature requests, and other issues. Want to help, just ask!

License

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

Latest podspec

{
    "name": "ApiSwift",
    "version": "0.2.0",
    "summary": "A library to call a specified function on a server from Swift 2.0",
    "description": "Call a function on a server with parameters as swift objects.nParameters are serialized, sent to the server, deserialized, then passed as arguments to the specific function",
    "homepage": "https://github.com/ckalnasy/ApiSwift",
    "license": "MIT",
    "authors": {
        "CKalnasy": "[email protected]"
    },
    "source": {
        "git": "https://github.com/ckalnasy/ApiSwift.git",
        "tag": "0.2.0"
    },
    "platforms": {
        "ios": "8.0"
    },
    "requires_arc": true,
    "source_files": "ApiSwift/*",
    "resource_bundles": {
        "ApiSwift": [
            "Pod/Assets/*.png"
        ]
    },
    "dependencies": {
        "SwiftSerialize": []
    }
}

Pin It on Pinterest

Share This