A lightweight utility built on top of AFNetworking for interacting with model objects over RESTful HTTP services.
Objective-C Ruby
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 3 commits ahead of yayuhh:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
Serializers/Mantle
YYHModelRouter
YYHModelRouterExample.xcodeproj
YYHModelRouterExample.xcworkspace
YYHModelRouterExample
YYHModelRouterExampleTests
.gitignore
LICENSE
Podfile
Podfile.lock
README.md
YYHModelRouter.podspec

README.md

YYHModelRouter

A lightweight utility built on top of AFNetworking for interacting with model objects over RESTful HTTP services. Provides endpoint-based configuration for automatically serializing JSON request/response payloads into model objects. By default Mantle is used to serialize model objects but custom model serializers can easily be built to work with any model framework.

Installation

pod "YYHModelRouter"

For use without Mantle install the core subspec.

pod "YYHModelRouter/core"

Usage

Adding Routes

Route responses of GET requests that match the path pattern @"/users/:userID" to the model class UserModel.

YYHModelRouter *modelRouter = [[YYHModelRouter alloc] initWithBaseURL:[NSURL URLWithString:@"http://foo.bar"]];
[modelRouter routeGET:@"/user/:userId" responseModelClass:[UserModel class] responseKeyPath:@"user"];

Requesting Model Data

Send a get request for @"/users/12345" and serialize the response as a UserModel object.

YYHModelRouter *modelRouter;
[modelRouter GET:@"/users/12345" parameters:nil success:^(NSURLSessionDataTask *task, id responseObject, id model) {
    UserModel *user = model;
    self.userView.nameLabel.text = user.name;
} failure:^(NSError *error) {

}];

Sending Model Data

Send a POST request and serialize the model as JSON in the request body.

Comment *comment = [[Comment alloc] init]
comment.message = @"YAYUHH";
[modelRouter POST:@"/comments" model:comment success:success failure:failure];