Java grammar checker quickstart
Send text to the edits endpoint. Sapling returns suggested replacements with character offsets so your application can review or apply each correction.
No language-specific SDK is required. The example uses a standard or commonly used HTTP client to call Sapling's JSON API.
Java
/api/v1/edits
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
String url = "https://api.sapling.ai/api/v1/edits";
String key = "<API_KEY>";
String params = "{\"key\":\""+key+"\", \"text\":\"Lets get started!\", \"session_id\":\"Test Document UUID\"}";
System.out.println(params);
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(params))
.build();
client.sendAsync(request, HttpResponse.BodyHandlers.ofString())
.thenApply(HttpResponse::body)
.thenAccept(System.out::println)
.join();
}
}
Example response
application/json
{
"edits": [
{
"start": 0,
"end": 4,
"replacement": "Let's",
"sentence": "Lets get started!",
"error_type": "R:OTHER"
}
]
}
Each edit identifies the source range and replacement text. Preserve the original offsets when applying more than one edit.
About Java
Java is a popular object-oriented programming language that can run across many different platforms through the Java Virtual Machine (JVM). Java has C/C++ style syntax but comes with automatic memory management and less low-level primitives.