• This repository has been archived on 17/Jan/2023
  • Stars
    star
    190
  • Rank 202,426 (Top 5 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created over 11 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Client for interacting with JSON-RPC APIs

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 invokeMethod:@"method.name"
    success:^(AFHTTPRequestOperation *operation, id responseObject)
{
    // ...
}   failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    // ...
}];

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

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

Using Protocol & NSProxy

Combine your JSON-RPC client with an Objective-C protocol for fun and profit!

@protocol ArithemeticProtocol
- (void)sum:(NSArray *)numbers
    success:(void (^)(NSNumber *sum))success;
    failure:(void (^)(NSError *error))failure;
@end

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

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

Subclassing

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

MyJSONRPCClient *client = [MyJSONRPCClient sharedClient];

[client 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.

More Repositories

1

AFNetworking

A delightful networking framework for iOS, macOS, watchOS, and tvOS.
Objective-C
33,326
star
2

AFIncrementalStore

1,687
star
3

AFOAuth2Manager

AFNetworking Extension for OAuth 2 Authentication
Objective-C
1,184
star
4

AFNetworkActivityLogger

AFNetworking 3.0 Extension for Network Request Logging
Objective-C
560
star
5

AFAmazonS3Manager

AFNetworking Client for the Amazon S3 API
Objective-C
364
star
6

fastlane

A fastlane setup to deploy Objective-C and Swift frameworks.
Ruby
251
star
7

Xcode-Project-Templates

Objective-C
221
star
8

AFHTTPRequestOperationLogger

AFNetworking Extension for HTTP Request Logging
Objective-C
215
star
9

AFOAuth1Client

AFNetworking Extension for OAuth 1.0a Authentication
Objective-C
210
star
10

AFgzipRequestSerializer

gzip Request Serializer for AFNetworking
Objective-C
166
star
11

AFRocketClient

152
star
12

AFOnoResponseSerializer

An XML and HTML response serializer for AFNetworking 2.0, using Ono
Objective-C
113
star
13

AFNetworking-ASIHTTPRequest

75
star
14

AFCoreImageResponseSerializer

AFNetworking 2.0 Serialization Module to apple Core Image Filters to Images
Objective-C
68
star
15

AFMsgPackSerialization

AFNetworking 2.0 Serialization Module for MsgPack
Objective-C
65
star
16

AFWebDAVManager

AFNetworking manager for WebDAV
Objective-C
63
star
17

WebKit-AFNetworking

AFNetworking Extensions for WebKit
Objective-C
48
star
18

AFContentRequestOperations

Legacy content-specific request operation subclasses re-implemented with AFNetworking 2.0 APIs
Objective-C
25
star
19

AFCollectionJSONRequestOperation

AFNetworking Extension for Collection+JSON Hypermedia
20
star
20

afnetworking.com

Source code for AFNetworking.com
CSS
8
star