Objective-C JSON-RPC Implementation
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Demiurgic JSON-RPC for Objective-C (iOS, Mac)

Demiurgic JSON-RPC is a lightweight and easy to use wrapper for making JSON-RPC 2.0 calls in Objective-C.

We're working to provide better documentation for the API. If you need assistance please feel free to contact us and we'll be glad to help!


  • iOS 5.0 or greater
  • XCode 4.4 or greater


  1. In your XCode Project, add all the .h and .m files from the Source folder into your project.
  2. Import DSJSONRPC.h in any file where you wish to make JSON-RPC web service calls.
  3. Starting consuming web services without all the hassle of managing the communication yourself!


Setting up the instance

First import the header file DSJSONRPC.h in the file you'd like to do web service calls from.

Once its included, simply create a new instance of the class in one of two ways:

  1. DSJSONRPC *jsonRPC = [[DSJSONRPC alloc] initWithServiceEndpoint:(NSString *)serviceEndpoint]; Service endpoint is the location of the web service where all calls will be made.
	DSJSONRPC *jsonRPC = [[DSJSONRPC alloc] initWithServiceEndpoint:[NSURL URLWithString:@"https://www.yourwebsite.com/MyWebservice.php"];
  1. DSJSONRPC *jsonRPC = [[DSJSONRPC alloc] initWithServiceEndpoint:(NSString *)serviceEndpoint andHTTPHeaders:(NSDictionary *)httpHeaders; The same as above, however you can specify customer HTTP headers to include with your request.
	NSDictionary *customHeaders = [NSDictionary dictionaryWithObjectsAndKeys:@"MyApplication/1.00", @"User-Agent", nil];
	DSJSONRPC *jsonRPC = [[DSJSONRPC alloc] initWithServiceEndpoint:[NSURL URLWithString:@"https://www.yourwebsite.com/MyWebservice.php" withHTTPHeaders:customHeaders];

Making a web service call

Demiurgic JSON-RPC can be used in one of two ways. The first is to use a more traditional approach with delegates, or with completion handler blocks. Using completion handlers is our recommendation for any new applications.

Lets assume our web service has a method called echo. It takes in dictionary with the key "message", which is a string that will be echoed back to the client.

  1. Completion Handler Based

    [jsonRPC callMethod:@"echo" withParameters:[NSDictionary dictionaryWithObjectsAndKeys:@"Hello, World!", @"message", nil] onCompletion:^(NSString *methodName, NSInteger callId, id methodResult, DSJSONRPCError methodError, NSError error) { // Use the server response data here. You should always ensure that methodError and error are nil first, and handle them accordingly. }];

  2. Delegate Based

    [jsonRPC callMethod:@"echo" withParameters:[NSDictionary dictionaryWithObjectsAndKeys:@"Hello, World!", @"message", nil]]; // All responses will be given to the delegate specified.