Giter Club home page Giter Club logo

luncheon's Introduction

Luncheon

CI Status Version License Platform

About

Luncheon is designed to have as minimal and simple setup as possible. Developing an app that communicates a REST API should be really simple. Other projects that try to tackle the same problems always end up with a lot of boiler-plate code or mapping relations.

At the moment, compatibility with a conventional Rails-served REST API is in mind. Maybe (hopefully) in the future, Luncheon will cover the majority of REST services. Feel free to send any pull requests!

Here are some of Luncheon's features:

  • Complete resource mapping between local/remote models

    • Route mapping: A Post model matches up to the route /posts.
    • The server's id property is automatically mapped to model.remoteId locally (or any other local variable if you want to override the default behavior).
    • Creating vs updating - depending on whether model.remote.id is present, calling save() will either create or update the resource (i.e. POST /posts or PATCH /posts/42).
    • Nested resource mapping.
    • When calling model.remote.save only the attributes that have been changed since being fetched will be sent up to the server.
    • Fields from JSON response are mapped directly to model properties. There is no manual JSON handling necessary (with the exception of a custom error handler).
    • Automatically maps snake_case properties to the Swift standard camelCase and vise-versa.
    • All network tasks are handled asyncronously.
  • Error handling

    • We sadly find a lot of developers actually completely overlook errors (especially when prototyping or MVPing), so we put in a no-setup default handler: By default, errors, from no-internet errors to validation errors with models, are alerted in an UIAlertView. Only the first error will be alerted as to avoid the end-user getting over-flooded.
    • Yet, still easily customisable (just set your own implemention to Luncheon.Options.errorHandler)
  • Easily get model property values as a dictionary with attributes() and attributesUnderscore()

  • Flexibility

    • Luncheon takes advantage of Swift protocol extensions, meaning that your Luncheon models can subclass other libraries, meaning you can use the same objects with CoreData or other third party libraries.

Usage

There is an example app included in the source.

Configuration can be as simple as supplying a baseUrl:

Luncheon.Options.baseUrl = "http://jsonplaceholder.typicode.com"

Defining a model:

class Post: NSObject, Lunch {
    dynamic var title : String?

    required override init() {
      super.init()
    }
}

Grab and print out list of posts:

// GET /posts
Post.remote.all { (posts: [Post] in
    for post in posts {
        println(post.title)
    }
}

Create a new post and print out the response resource's attributes:

let myPost = Post()
myPost.title = "Wow, Luncheon saves me so much time"

// POST /posts
myPost.remote.save { post in
	println(post.attributes())
}

Grab an existing post and print its attributes:

// GET /posts/42
Post.remote.find(42) { post in println(post.attributes()) }

Or some associated comments on a post:

// GET /posts/42/comments
post.remote.associated(Comment.self).all { (comments: [Comment]) in
    for comment in comments {
        println(comment.title)
    }
}

Installation

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

pod "Luncheon", git: "https://github.com/Dan2552/Luncheon.git"

Main Contributors

License

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

luncheon's People

Contributors

dan2552 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

planerde

luncheon's Issues

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.