Skip to content

boecko/AFJSONRPCClient

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AFJSONRPCClient

A JSON-RPC Client built on AFNetworking

JSON-RPC is a remote procedure call protocol encoded in JSON. It is a simple protocol (and very similar to XML-RPC), defining only a handful of data types and commands. JSON-RPC allows for notifications (info sent to the server that does not require a response) and for multiple calls to be sent to the server which may be answered out of order.

Example Usage

AFJSONRPCClient *client = [AFJSONRPCClient clientWithEndpointURL:[NSURL URLWithString:@"http://path.to/json-rpc/service/"]];

// Invocation
[client invokeWithMethod:@"method.name" 
    success:^(AFHTTPRequestOperation *operation, id responseObject) 
{
    // ...
}   failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    // ...
}];

// Invocation with Parameters
[client invokeWithMethod:@"method.name" 
              parameters:@{@"foo" : @"bar", @"baz" : @(13)}
    success:^(AFHTTPRequestOperation *operation, id responseObject) {
    // ...
}   failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    // ...
}];

// Invocation with Parameters and Request ID
[client invokeWithMethod:@"method.name" 
              parameters:@[@(YES), @(42)] 
               requestId:@(2) 
    success:^(AFHTTPRequestOperation *operation, id responseObject) {
    // ...
}   failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    // ...
}];

Subclassing

You may subclass AFJSONRPCClient for shared class and service-related methods:

MyJSONRPCClient *client = [MyJSONRPCClient sharedClient];

[client sum:@[@(1), @(2)]
    success:^(NSNumber *sum) {
    // ...
}   failure:^(NSError *error) {
    // ...
}];

Using Protocol and NSProxy (no need for an own subclass)

@protocol MyJSONRPCProtocol
- (void)sum:(NSArray *)numbers
            success:(afproxy_success_callback_t) success
            failure:(afproxy_failure_callback_t) failure;
@end

id<MyJSONRPCProtocol> proxy = [AFJSONRPCProxy proxyWithEndpointURL:[NSURL URLWithString:@"http://path.to/json-rpc/service/"] 
											  protocol:@protocol(MyJSONRPCProtocol)];

[proxy sum:@[@(1), @(2)]
    success:^(NSNumber *sum) {
    // ...
}   failure:^(NSError *error) {
    // ...
}];

Installation

CocoaPods is the recommended way to add AFJSONRPCClient to your project.

Here's an example podfile that installs AFJSONRPCClient and its dependency, AFNetworking.

Podfile

platform :ios, '5.0'

pod 'AFJSONRPCClient', '0.1.0'

Note the specification of iOS 5.0 as the platform; leaving out the 5.0 will cause CocoaPods to fail with the following message:

[!] AFJSONRPCClient is not compatible with iOS 4.3.

License

AFJSONRPCClient and AFNetworking are available under the MIT license. See the LICENSE file for more info.

About

Client for interacting with JSON-RPC APIs

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Objective-C 96.6%
  • Ruby 3.4%