io.resourcepool:jarpic-client

JSON RPC 2.0. Client

Лицензия

Лицензия

Категории

Категории

CLI Взаимодействие с пользователем
Группа

Группа

io.resourcepool
Идентификатор

Идентификатор

jarpic-client
Последняя версия

Последняя версия

1.1.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

io.resourcepool:jarpic-client
JSON RPC 2.0. Client
Ссылка на сайт

Ссылка на сайт

https://github.com/resourcepool/jarpic-client
Система контроля версий

Система контроля версий

https://github.com/resourcepool/jarpic-client.git

Скачать jarpic-client

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/io.resourcepool/jarpic-client/ -->
<dependency>
    <groupId>io.resourcepool</groupId>
    <artifactId>jarpic-client</artifactId>
    <version>1.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/io.resourcepool/jarpic-client/
implementation 'io.resourcepool:jarpic-client:1.1.0'
// https://jarcasting.com/artifacts/io.resourcepool/jarpic-client/
implementation ("io.resourcepool:jarpic-client:1.1.0")
'io.resourcepool:jarpic-client:jar:1.1.0'
<dependency org="io.resourcepool" name="jarpic-client" rev="1.1.0">
  <artifact name="jarpic-client" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.resourcepool', module='jarpic-client', version='1.1.0')
)
libraryDependencies += "io.resourcepool" % "jarpic-client" % "1.1.0"
[io.resourcepool/jarpic-client "1.1.0"]

Зависимости

compile (5)

Идентификатор библиотеки Тип Версия
com.google.code.findbugs : jsr305 jar 3.0.2
com.fasterxml.jackson.core : jackson-core jar 2.9.0
com.fasterxml.jackson.core : jackson-annotations jar 2.9.0
com.fasterxml.jackson.core : jackson-databind jar 2.9.0
com.squareup.okhttp3 : okhttp jar 3.8.1

test (1)

Идентификатор библиотеки Тип Версия
junit : junit jar 4.12

Модули Проекта

Данный проект не имеет модулей.

jarpic-client

A Simple JSON-RPC 2.0 Java Client using Jackson and OkHttp

This library works on Android as well

It contains both synchronous and asynchronous APIs.

Build Status

Add it to your project

Maven:

<!-- https://mvnrepository.com/artifact/io.resourcepool/jarpic-client -->
<dependency>
    <groupId>io.resourcepool</groupId>
    <artifactId>jarpic-client</artifactId>
    <version>1.1.0</version>
</dependency>

Gradle:

compile 'io.resourcepool:jarpic-client:1.1.0'

Usage

Send single JSON-RPC request:

JsonRpcClient client = new HttpJsonRpcClient(endpoint);
JsonRpcRequest req = JsonRpcRequest.builder()
  .method("cmd::execCmd")
  .param("param1", "myvalue1")
  .param("param2", "myvalue2")
  .build();
  
// With your own Result class POJO  
JsonRpcResponse<Result> res = client.send(req, Result.class);
System.out.println("Response is:");
System.out.println(res);

Send multiple JSON-RPC requests:

JsonRpcClient client = new HttpJsonRpcClient(endpoint);
JsonRpcRequest req1 = JsonRpcRequest.builder()
  .method("cmd::execCmd")
  .param("param1", "myvalue1")
  .param("param2", "myvalue2")
  .build();

JsonRpcRequest req2 = JsonRpcRequest.builder()
  .method("cmd::resumeCmd")
  .param("key", "value")
  .build();
  
List<JsonRpcRequest> reqs = JsonRpcRequest.combine(req1, req2);
  
// With your own Result class POJO  
List<JsonRpcResponse<Result>> res = client.send(reqs, Result.class);
System.out.println("Response is:");
System.out.println(res);

Send single JSON-RPC Notification

JsonRpcClient client = new HttpJsonRpcClient(endpoint);
JsonRpcRequest req = JsonRpcRequest.notifBuilder()
  .method("cmd::execCmd")
  .param("param1", "myvalue1")
  .param("param2", "myvalue2")
  .build();
  
// With your own Result class POJO  
JsonRpcResponse<Result> res = client.send(req, Result.class);
System.out.println("Response is:");
System.out.println(res);

All these methods can also be called asynchronously by providing an extra parameter.

Simple Example:

JsonRpcClient client = new HttpJsonRpcClient(endpoint);
JsonRpcRequest req = JsonRpcRequest.builder()
  .method("cmd::execCmd")
  .param("param1", "myvalue1")
  .param("param2", "myvalue2")
  .build();
  
client.send(req, String.class, new JsonRpcCallback() {
      @Override
      public void onResponse(@Nullable JsonRpcResponse res) {
        System.out.println("Response is:");
        System.out.println(res);
      }

      @Override
      public void onFailure(IOException ex) {
        System.err.println("Something bad happened: " + ex.getMessage());
      }
    });

Example with custom deserializer:

JsonRpcRequest req = JsonRpcRequest.builder()
      .method("cmd::start")
      .param("apiKey", apiKey)
      .build();

client.send(req, Result.class, new JsonRpcCallback<Result>() {
      @Override
      public void onResponse(@Nullable JsonRpcResponse<Result> res) {
        // With your own Result class POJO  
        System.out.println(res.getResult());
      }

      @Override
      public void onFailure(IOException ex) {
        System.err.println("Something bad happened: " + ex.getMessage());
      }
    });

License

Copyright 2017 Resourcepool

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

io.resourcepool

resourcepool

Training content, slides, presentations, workshops, opensource projects. By anyone, for everyone, for free.

Версии библиотеки

Версия
1.1.0
1.0.0