Let‘s develop a Steemit API Wrapper for Java

View this thread on: d.buzz | hive.blog | peakd.com | ecency.com
·@dez1337·
0.000 HBD
Let‘s develop a Steemit API Wrapper for Java
Hay Steemers,

I would like to provide some new tools to the Steemit univers and as you may have noticed due to my posts here, my preferred programming language is Java. But, so far there is no kind of API Wrapper for Steemit which makes it pretty hard to develop new tools to me.

![WRAPPER](https://kemptechnologies.com/blog/wp-content/uploads/2015/07/JAVA-API-Wrapper.png)
[Source](https://kemptechnologies.com/blog/wp-content/uploads/2015/07/JAVA-API-Wrapper.png)

Because of that, I’ve spend some time to do a short proof of concept which you can find later in this article. My main question for now is, are there people out there that are also interested in a Java API for Steemit or are there even people who would like to contribute? If so, please leave a comment right here so I know if the work is worth it. Please keep in mind that this API wrapper could also be usefull for android apps.

If I feel like this project is worth the work, I will create a new GitHub repository for the project so everybody could help to make this small project a success.

# Proof of Concept
For this proof of concept I’ve used the “tyrus-standalone-client” for the websocket communication in Java. So far, this is the only dependency that is needed so far, which makes the pom pretty easy to understand:

```XML
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>dez1337.steemit.com</groupId>
	<artifactId>steemit-api-wrapper</artifactId>
	<version>1.0-SNAPSHOT</version>
	<name>Steemit Java API Wrapper</name>
	<url>http://www.steemit.com/@dez1337</url>

	<dependencies>
		<dependency>
			<groupId>org.glassfish.tyrus.bundles</groupId>
			<artifactId>tyrus-standalone-client</artifactId>
			<version>1.13</version>
		</dependency>
	</dependencies>
	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.6.0</version>
				<configuration>
					<source>${java.version}</source>
					<target>${java.version}</target>
				</configuration>
			</plugin>
		</plugins>
	</build>
	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

		<java.version>1.8</java.version>
	</properties>
</project>
```

After that I’ve created one simple Java class that only do one websocket request. Here is the code of this class:

```Java
package dez.steemit.com;

import java.io.IOException;
import java.net.URI;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import javax.websocket.ClientEndpointConfig;
import javax.websocket.Endpoint;
import javax.websocket.EndpointConfig;
import javax.websocket.MessageHandler;
import javax.websocket.Session;

import org.glassfish.tyrus.client.ClientManager;


public class JavaAPIWrapper {
	private static CountDownLatch messageLatch;
	private static final String SENT_MESSAGE = "{\"jsonrpc\": \"2.0\", \"params\": [\"database_api\", \"get_account_count\", [1]], \"id\": 1 \"method\": \"call\"}";

	public static void main(String[] args) {
		try {
			messageLatch = new CountDownLatch(1);

			final ClientEndpointConfig cec = ClientEndpointConfig.Builder.create().build();

			ClientManager client = ClientManager.createClient();
			client.connectToServer(new Endpoint() {

				@Override
				public void onOpen(Session session, EndpointConfig config) {
					try {
						session.addMessageHandler(new MessageHandler.Whole<String>() {

							@Override
							public void onMessage(String message) {
								System.out.println("Received message: " + message);
								messageLatch.countDown();
							}
						});
						session.getBasicRemote().sendText(SENT_MESSAGE);
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
			}, cec, new URI("wss://node.steem.ws"));
			messageLatch.await(100, TimeUnit.SECONDS);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

```

If you run the application, it print something like this:

> Received message: {"id":1,"result":121305}

So everything is working as expected!

At this point I have to say thanks to @aglo whose article showed me how to format the websocket requests and also a huge thanks to @xeroc and @jesta for providing the service “node.steem.ws”.

# Summary
Please do not forget to give me some feedback for the idea and make sure to follow me by pressing the button below, so you’ll never miss new posts!

[![alt text](http://www.vector-eps.com/wp-content/gallery/follow-me-twitter-buttons-and-icons/follow-me-twitter-buttons-and-icons6.jpg)](https://steemit.com/@dez1337)
[Source](http://www.vector-eps.com/wp-content/gallery/follow-me-twitter-buttons-and-icons/follow-me-twitter-buttons-and-icons6.jpg)


Thank you and best regards!
👍 , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,