Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

What's New in HTTP-RPC?

DZone's Guide to

What's New in HTTP-RPC?

The latest release of HTTP-RPC is now available! Come take a look at a couple key updates included in this release, including how to make use of them.

· Integration Zone
Free Resource

Modernize your application architectures with microservices and APIs with best practices from this free virtual summit series. Brought to you in partnership with CA Technologies.

HTTP-RPC 4.2 is now available for download, as well as via Cocoapods for iOS and Maven for Java:

<dependency>
    <groupId>org.httprpc</groupId>
    <artifactId>httprpc</artifactId>
    <version>...</version>
</dependency>


This release includes the following updates:

  • Refine invocation methods for Swift. Invocation methods are now parameterized, so it is no longer necessary to cast the return value to the desired type: 


    open func invoke<T>(_ method: String, path: String, 
        resultHandler: @escaping (T?, Error?) -> Void) -> URLSessionTask? { ... }
    
    open func invoke<T>(_ method: String, path: String, arguments: [String: Any], 
        resultHandler: @escaping (T?, Error?) -> Void) -> URLSessionTask? { ... }

    For example:
    serviceProxy.invoke("GET", path: "/example") { (result: UIImage?, error) in
        // Handle image result
    }


  • Add support for custom response handlers. Callers can now perform custom deserialization via a response handler callback. In Swift, the callback is a closure: 
    open func invoke<T>(_ method: String, path: String, arguments: [String: Any],
        responseHandler: @escaping (Data, String) throws -> T?,
        resultHandler: @escaping (T?, Error?) -> Void) -> URLSessionTask? { ... }


    For example (using JSONDecoder to return a strongly typed result):
    serviceProxy.invoke("GET", path: "/example", arguments: [:], responseHandler: { data, contentType in
        let decoder = JSONDecoder()
    
        return try? decoder.decode(Example.self, from: data)
    }) { (result: Example?, error) in
        // Handle custom result
    }


    In Java, the callback is defined as follows:
    public interface ResponseHandler<V> {
        public V decode(InputStream inputStream, String contentType) throws IOException;
    }


    For example (using Jackson to return a strongly typed result):
    serviceProxy.invoke("GET", "/example", mapOf(), (inputStream, contentType) -> {
        ObjectMapper objectMapper = new ObjectMapper();
    
        return objectMapper.readValue(input, Example.class);
    }, (Example result, Exception exception) -> {
        // Handle custom result
    });    


For more information, see the project README.

The Integration Zone is proudly sponsored by CA Technologies. Learn from expert microservices and API presentations at the Modernizing Application Architectures Virtual Summit Series.

Topics:
java ,http-rpc ,invocation methods ,swift ,callbacks

Published at DZone with permission of Greg Brown, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}