Nativegen is a source code generator of native app accessing REST API. This can reduce your dull works at all. If you use Phoenix framework, this is for you.
It is supported just Swift code yet, but will Android, Unity and so on.
Installation
You can add dependency to your project's mix.exs.
defp deps do
[
{:nativegen, "~> 0.4.0"}
]
endthen,
$ mix do deps.get, compileiOS
Generating code depends on the follwoing library
Example generating source code
import Foundation
import BrightFutures
import Alamofire
import SwiftyJSON
public class User : NSObject, JsonModel {
var id: Int
let username: String
var items: [Item]
public required init(json: JSON) {
id = json["id"].int
username = json["username"].stringValue
if json["items"].error == nil {
items = json["items"].arrayValue.map { Item(json: $0) }
}
}
}
public class UserRepository : Repository {
public func create(username: String) -> Future<User, NSError> {
return requestData(.POST, routes: "/api/users", param: ["user": ["username": username]])
}
public func show(id: Int) -> Future<User, NSError> {
return requestData(.GET, routes: "/api/users/\(id)", param: nil)
}
public func update(id: Int, username: String) -> Future<User, NSError> {
return requestData(.PATCH, routes: "/api/users/\(id)", param: ["user": ["username": username]])
}
public func delete(id: Int) -> Future<Bool, NSError> {
return requestSuccess(.DELETE, routes: "/api/users/\(id)", param: nil)
}
public func buyItem(itemId: Int) -> Future<Bool, NSError> {
return requestSuccess(.POST, routes: "/users/buy", param: ["item_id": itemId])
}
}Usage(Swift)
First, you have to setup.
$ mix nativegen.swift.setup /your/to/your/directoryNext, following command will generate accessible REST API swift code.
$ mix nativegen.swift.create /path/to/your/directory User users username:string group:Group items:array:ItemAnd, generate Json model the following command.
$ mix nativegen.swift.model Item name:string strength:integerAlso, append model in your swift code.
$ mix nativegen.swift.model Item name:string strength:integer --file /path/to/your/repo.swiftYou can also generate methods
$ mix nativegen.swift.method post /api/chat/response responseMessage Chat thread_id:integer message:stringLisence
MIT Lisence