PCJSONRPC

Simple yet extensible synchronous JSON-RPC client.

It's simple. Maybe so simple that it probably is not feature complete or even spec compliant. But it works for real world projects.

It's extensible because easily subclassable. Redefine one or all of the methods used in the process.

It's synchronous because sometime we know what we want and we know what we do. And we certainly know not to invoke a remote method on the main thread, right?

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

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

pod "PCJSONRPC"

Usage

Create a JSON-RPC client

NSURL *url = [NSURL URLWithString:@"http://example.com/json-rpc"];
PCJSONRPC *jsonRPC = [[PCJSONRPC alloc] initWithURL:url];

Invoke a method

NSError *error;
NSString *hello = [jsonRPC invokeMethod:@"echo"
                         withParameters:@[@"World!"]
                                  error:&error];

Define a protocol

@protocol EchoService
- (id)echo:(id)params error:(NSError **)error;
@end

Create a proxy

id<EchoService> service =
    [jsonRPC proxyForProtocol:@protocol(EchoService)];

Invoke a method

hello = [service echo:@[@"World!"] error:&error];

Author

Pierre-David Bélanger, pierredavidbelanger@gmail.com

License

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