Sapling Logo
Grammar API quickstart

Kotlin / Android Grammar Checker

Add spelling and grammar suggestions to a Kotlin / Android application with Sapling's edits API.

  • HTTPS POST
  • HTTP API
  • API key required
POST Kotlin / Android logo Kotlin / Android /api/v1/edits

Kotlin / Android 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.
Kotlin / Android /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 Kotlin / Android

Kotlin is a programming language that interoperates with Java on the JVM. While it is cross-platform, widespread adoption of Kotlin stems from its first-class support on the Android platform for Android applications.