Giter Club home page Giter Club logo

afjsonrpcclient's Introduction

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.

afjsonrpcclient's People

Contributors

avfonarev avatar boecko avatar dal-papa avatar mattt avatar mspasov avatar wiistriker avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

afjsonrpcclient's Issues

FeatureRequest: Proxy with forwardInvocation/methodSignatureForSelector

Wouldn't this be a much nicer implemenation instead of subclassing AFJSONRPCClient.
There isn't realy the need for creating a local class for a remote object, a Protocol should work.

Example

@protocol MyProtocol
- (id) sum( NSArray* ) args  success:(void (^)(NSNumber *sum))success
    failure:(void (^)(NSError *error))failure;
@end

id<MyProtocol> client = [AFJSONRPCClient proxyWithEndpointURL:[NSURL URLWithString:@"http://path.to/json-rpc/service/"]];

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

Via forwardInvocation/methodSignatureForSelector this could be handled in an elegant way.

cancel call

Hello,

I was trying to to cancel a call in progress. At least to avoid the competition blocks to be called when the results are no longer needed.

It seems to me that the pattern in AFNetworking was to call NSOperation's cancel. This doesn't seem to work because - (void)invokeMethod:(NSString *)method... doesn't return the underlying operation.

Should one expose the underlying HTTPRequestOperationWithRequest:success:failure: in order to achieve this behavior ? This method doesn't seem to check if the operation is canceled before calling the success / failure handlers.

Thank you

com.alamofire.networking.json-rpc Code=-32602

Error Domain=com.alamofire.networking.json-rpc Code=-32602 "invalid argument 0: json: cannot unmarshal hex string without 0x prefix into Go value of type common.Address" UserInfo={NSLocalizedDescription=invalid argument 0: json: cannot unmarshal hex string without 0x prefix into Go value of type common.Address}

Version control marker in file

Hello,
Just updated to the latest version AFJSONRPCClient (0.4.0) and thought that you should know that there is an issue in the source code.

  1. Error: Version control marker in file. In AFJSONRPCClient.h you have the following:
    <<<<<<< HEAD

- (id)proxyWithProtocol:(Protocol *)protocol;

  • (NSMutableURLRequest *)requestWithMethod:(NSString *)method
    parameters:(id)parameters
    requestId:(id)requestId;

795eff0

Thanks,
Yury

How to change Content-Type?

By default the rpc client sends application/json, but I want to send application/json-rpc.
How to change Content-Type?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.