Reason - Example - Installation
let ws = WS("http://jsonplaceholder.typicode.com")
ws.get("/users").then { json in
// Get back some json \o/
}
Because JSON apis are used in 99% of iOS Apps, this should be simple.
We developers should focus on our app logic rather than boilerplate code .
Less code is better code
By providing a lightweight client that automates boilerplate code everyone has to write.
By exposing a delightfully simple api to get the job done simply, clearly, quickly.
Getting swift models from a JSON api is now a problem of the past
- Simple
- Lightweight (1 file)
- Pure Swift
- No magic involved
- Strongly Typed
- Chainable
- Uses popular Promise/Future concept
import ws
let ws = WS("http://jsonplaceholder.typicode.com")
ws.get("/users").then { json in
print(json)
}
func latestUsers() -> Promise<[User]> {
return ws.get("/users")
}
extension User:ArrowParsable {
init(json: JSON) {
identifier <-- json["id"]
username <-- json["username"]
email <-- json["email"]
}
}
latestUsers().then { users in
print(users) // STRONGLY typed [Users] ❤️
}
In your Cartfile
github "s4cha/ws"
- Run
carthage update
- Drag and drop
ws.framework
fromCarthage/Build/iOS
toLinked Frameworks and Libraries
(“General” settings tab) - Go to
Project
>Target
>Build Phases
+New run Script Phase
/usr/local/bin/carthage copy-frameworks
Add input files
$(SRCROOT)/Carthage/Build/iOS/ws.framework
$(SRCROOT)/Carthage/Build/iOS/Alamofire.framework
$(SRCROOT)/Carthage/Build/iOS/Arrow.framework
$(SRCROOT)/Carthage/Build/iOS/then.framework
This links ws and its dependencies.
And voila !
ws is part of a series of lightweight libraries aiming to make developing iOS Apps a breeze :