The FastComments Java SDK. You can use this to build secure and scalable backend applications that interact with FastComments, or build reactive client applications.
Add the Repsy repository to your project's POM:
<repositories>
<repository>
<id>repsy</id>
<name>FastComments Maven Repository on Repsy</name>
<url>https://repo.repsy.io/mvn/winrid/fastcomments</url>
</repository>
</repositories>Then add the dependencies you need:
<dependencies>
<!-- API Client -->
<dependency>
<groupId>com.fastcomments</groupId>
<artifactId>client</artifactId>
<version>1.0.0</version>
</dependency>
<!-- Core Library (includes SSO) -->
<dependency>
<groupId>com.fastcomments</groupId>
<artifactId>core</artifactId>
<version>1.0.0</version>
</dependency>
<!-- PubSub Library (for live events) -->
<dependency>
<groupId>com.fastcomments</groupId>
<artifactId>pubsub</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>Add the Repsy repository to your build.gradle file:
repositories {
mavenCentral()
maven {
url "https://repo.repsy.io/mvn/winrid/fastcomments"
}
}
dependencies {
// API Client
implementation "com.fastcomments:client:1.0.0"
// Core Library (includes SSO)
implementation "com.fastcomments:core:1.0.0"
// PubSub Library (for live events)
implementation "com.fastcomments:pubsub:1.0.0"
}This library contains three modules. The generated API client, the core Java library which contains hand-written utilities
to make working with the API easier, and the pubsub module which is a library for subscribing to change feeds.
For the API client, there are two classes, DefaultApi and PublicApi. The DefaultApi contains methods that require your API key, and PublicApi contains api calls
that can be made directly from a browser/mobile device/etc without authentication.
Important: You must set your API key on the ApiClient before making authenticated requests. If you don't, requests will fail with a 401 error.
import com.fastcomments.invoker.ApiClient;
import com.fastcomments.invoker.ApiException;
import com.fastcomments.api.DefaultApi;
import com.fastcomments.model.*;
public class Example {
public static void main(String[] args) {
// Create and configure the API client
ApiClient apiClient = new ApiClient();
// REQUIRED: Set your API key (get this from your FastComments dashboard)
apiClient.setApiKey("YOUR_API_KEY_HERE");
// Create the API instance with the configured client
DefaultApi api = new DefaultApi(apiClient);
// Now you can make authenticated API calls
try {
// Example: Add an SSO user
CreateAPISSOUserData userData = new CreateAPISSOUserData();
userData.setId("user-123");
userData.setEmail("user@example.com");
userData.setDisplayName("John Doe");
AddSSOUserAPIResponse response = api.addSSOUser("YOUR_TENANT_ID", userData)
.execute();
System.out.println("User created: " + response);
} catch (ApiException e) {
System.err.println("Error: " + e.getResponseBody());
// Common errors:
// - 401: API key is missing or invalid
// - 400: Request validation failed
}
}
}Public endpoints don't require authentication:
import com.fastcomments.api.PublicApi;
import com.fastcomments.invoker.ApiException;
PublicApi publicApi = new PublicApi();
try {
var response = publicApi.getCommentsPublic("YOUR_TENANT_ID", "page-url-id")
.execute();
System.out.println(response);
} catch (ApiException e) {
e.printStackTrace();
}- 401 "missing-api-key" error: Make sure you call
apiClient.setApiKey("YOUR_KEY")before creating the DefaultApi instance. - Wrong API class: Use
DefaultApifor server-side authenticated requests,PublicApifor client-side/public requests. - Null API key: The SDK will silently skip authentication if the API key is null, leading to 401 errors.
You'll see you're supposed to pass a broadcastId in some API calls. When you receive events, you'll get this ID back, so you know to ignore the event if you plan to optimistically apply changes on the client
(which you'll probably want to do since it offers the best experience). Pass a UUID here. The ID should be unique enough to not occur twice in a browser session.