Coder Social home page Coder Social logo

ws's Introduction

ws ☁️ - Elegant JSON WebService in Swift

Language: Swift 2 Platform: iOS 8+ Carthage compatible License: MIT Build Status Release version

Reason - Example - Installation

let ws = WS("http://jsonplaceholder.typicode.com")

ws.get("/users").then { json in
    // Get back some json \o/
}

Why

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

How

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

What

  • Simple
  • Lightweight (1 file)
  • Pure Swift
  • No magic involved
  • Strongly Typed
  • Chainable
  • Uses popular Promise/Future concept

Usage

Import ws at the top of your file

import ws

Set webservice base URL

let ws = WS("http://jsonplaceholder.typicode.com")

Get back some json instantly \o/

ws.get("/users").then { json in
    print(json)
}

Design your Api

func latestUsers() -> Promise<[User]> {
    return ws.get("/users")
}

Tell ws how to map your user models

extension User:ArrowParsable {
    init(json: JSON) {
        identifier <-- json["id"]
        username <-- json["username"]
        email <-- json["email"]
    }
}

Get back some sweet swift models ❤️

latestUsers().then { users in
    print(users) // STRONGLY typed [Users] ❤️
}

Installation

Carthage

In your Cartfile

github "s4cha/ws"
  • Run carthage update
  • Drag and drop ws.framework from Carthage/Build/iOS to Linked 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 !

Other repos ❤️

ws is part of a series of lightweight libraries aiming to make developing iOS Apps a breeze :

ws's People

Contributors

s4cha avatar tmcw avatar

Watchers

Chew Chit Siang avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.