Git Product home page Git Product logo

repeson's Introduction

repeson

A JSON-RPC Client for Java. It uses the HttpClient of JDK11, so requests can be sent either blocking (synchronous) or not blocking (asynchronous)

How to use it

1. Adding the dependency to your project

<dependency>
  <groupId>com.emiperez.repeson</groupId>
  <artifactId>repeson</artifactId>
  <version>0.5.0</version>
</dependency>

2. Configuring the Transport

  1. Currently only HTTP/HTTPS Transport has been developed.
  2. Create a new HttpClient and Configure it with any HTTP related properties (Authentication, Proxy, Cookie Handler, SSL and so on)
  3. Build a new HttpTransport and inject the HttpClient to it
Transport transport = HttpTransport.builder(httpClient).uri(uri).contentType(contentType).build();

3. Building the JsonRpcClient

JsonRpcClient jsonRpcClient = JsonRpcClient.builder()
					.transport(transport)
					.version(JsonRpcVersion.v2_0)
					.idGenerator(idGenerator)
					.build();

4.- Sending the Request and getting the Response

Synchronous or blocking:

JsonRpcResponse<Customer> r = jsonRpcClient.sendRequestWithDefaults("getcustomer", paramsPojo);
r.ifHasResultOrElse(customer -> System.out.println(customer.getName(),
								() -> System.out.println("No customer returned"));

or Asynchronous (not blocking)

CompletableFuture<Customer> cc = jsonRpcClient
  .sendRequestWithDefaultsAsync("getcustomer", paramsPojo)
  .thenApply(JsonRpcResponse::getResult);

If the returned Type uses Generics, for example; ArrayList<Customer>, to prevent the Type Erasure, a class file, that extends JsonRpcResponse must be created,

public class CustomerListResponse extends JsonRpcResponse<ArrayList<Customer>> {}

and passed as an argument to send methods:

CustomerListResponse r = jsonRpcClient.sendRequestWithDefaults("listcustomers", paramsPojo, 
								CustomerListResponse.class);
if (r.hasResult()) {
  ArrayList<Customer> cs = r.getResult();
  //Do whatever with cs
}

repeson's People

Contributors

emiperez avatar

Stargazers

 avatar  avatar

Watchers

 avatar

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.