Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/eliasstar/jsonrpc4j

A general JSON-RPC 2.0 Wrapper for Java
https://github.com/eliasstar/jsonrpc4j

gson json-rpc maven

Last synced: 6 days ago
JSON representation

A general JSON-RPC 2.0 Wrapper for Java

Awesome Lists containing this project

README

        

# JsonRpc4J
> A general JSON-RPC 2.0 Wrapper for Java

## Downloads
### Jar
Releases can be downloaded [here](https://github.com/EliasStar/JsonRpc4J/releases).
The javadoc can be found in the "javadoc" suffix jar and the "sources" suffix jar includes the raw, uncompiled source code for reference.

### Maven
#### pom.xml
Add the following under `project/repositories` tag:
```xml

github
JsonRpc4J GitHub Maven Packages
https://maven.pkg.github.com/EliasStar/JsonRpc4J

```
Furthermore add the following under `project/dependencies` tag:
```xml

eliasstar
json-rpc
VERSION

```
Replace `VERSION` with a version found under releases, preferably the latest.

#### settings.xml
Is located under `~/.m2/settings.xml`.
Add the following under `settings/servers` tag:
```xml

github
YOUR_USERNAME
YOUR_PERSONAL_ACCESS_TOKEN

```
Be sure to replace `YOUR_USERNAME` and `YOUR_PERSONAL_ACCESS_TOKEN`.

## Usage
### Get a connection
```java
// Simple
var con = JsonRpc.connect("https://example.com/jsonrpc.do");
```
```java
// Customizable
var client = HttpClient.newHttpClient();
var gson = new Gson();

var con = new ConnectionBuilder(client, "https://example.com/jsonrpc.do").setGson(gson).build();
```

### Make a request
```java
// Remote procedure call
var result = con.callRemoteProcedure("exampleMethod");
```
```java
// With parameters
var params = new JsonArray();

params.add("foo");
params.add(42);

var result = con.callRemoteProcedure("exampleMethod", params);
```
```java
// Notification
con.sendNotification("exampleNotification");
```

```java
// Batch request
var results = con.sendBatchRequest(
new Request(0, "firstMethod"),
new Request(1, "secondMethod"),
new Notification("exampleNotification")
);
```

## License
JsonRpc4J - A general JSON-RPC 2.0 Wrapper for Java

Copyright (C) 2020-2021 Elias*

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see .