Java (Backend)
The Java SDK for backends
Introduction
The Java SDK is a backend SDK that can be used to communicate with Mitter.io. It provides the following high level functionalities:
Create and delete Users
Create and delete Channels
Get and send Messages
Get and send Timeline Events
Being a backend SDK, the Java SDK connects with Mitter.io via HTTP only.
Getting the SDK
The Java SDK is available on jcenter. Add this to you build.gradle
:
Configuring the Client
The main point of access is the MitterCentralClientFactory
. Create the factory like so:
This will authenticate you with an Application Principal. This is the most common type of credential you will need when you make calls from your backend.
You can also authenticate as:
The Subscriber (the entity you created you Mitter.io account with) using
MitterSubscriberApiAccessCredentials
A User, using
MittterUserTokenCredentials
Anonymously, using
MitterAnonymousCredentials
Do note that each principal has restricted access to APIs. A Subscriber, for instance, cannot send Messages to a Channel, and an Application cannot create other Applications.
Refer to the Platform Reference docs for the full list of operations each Principal can perform.
Access Mitter.io
You can access the different clients
using MitterCentralClientFactory
User Operations
Users operations are done through the MitterUsersClient
, as follows:
Channel Operations
Channel operations are performed using the MitterChannelsClient
, which can be acquired and used as follows:
Message Operations
Send Messages using the MitterMessagesClient
:
Send custom payloads:
Get very specific messages with a query:
Other Operations
The SDK has a few other clients for operations on Timeline Events, User Presence, Channel Streams, etc.
The APIs are very similar to the ones shown above, and you should have no problem navigating through them.
High Level Clients
Certain APIs on Mitter.io are paginated, like Channels and Messages. So when you do something like messagesClient.getMessagesFromChannel(channelId)
you will only get the default 50 messages, and to get more messages, you will have to build a query and call getMessagesFromChannel
.
The SDK makes it easy to use these paginated APIs without worrying about the pagination scheme or maintaining the pagination tokens, by providing high level clients.
The MitterMessagesHlcClient
provides the following convenience functions:
getAllExistingMessages(channelId)
getAllMessagesAfter(channelId, messageId)
getAllMessagesBefore(channelId, messageId)
You don't need to worry about these functions being intensive operations, because they provide lazy lists.
High Level Clients return Iterator
s, so more pages will not be fetched unless you iterate and reach the end.
Notes
The SDK is itself written in Kotlin, and fully supports most JVM languages
To be able to send JSON in custom payloads, the SDK uses
JsonNode
from Jackson
Last updated