Scala 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.
Scala
/api/v1/edits
This is an example of doing an HTTP Post request using scalaj-http, which is now deprecated
import scalaj.http.{Http, HttpOptions}
object Main {
def main(args: Array[String]): Unit = {
println("Hello world!")
val data : String = """{"key":"API_KEY","text":"Lets get started", "session_id": "Test Document UUID"}"""
val url : String = "https://api.sapling.ai/api/v1/edits"
val result = Http(url).postData(data)
.header("Content-Type", "application/json")
.header("Charset", "UTF-8")
.option(HttpOptions.readTimeout(30000)).asString
}
}
You can also use the native Java HTTPClient to reduce dependancies
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
object Main {
def main(args: Array[String]): Unit = {
println("Hello world!")
val params : String = """{"key":"API_KEY","text":"Lets get started", "session_id": "Test Document UUID"}"""
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 Scala
Scala is a programming language designed to run on the JVM, supporting both functional and object-oriented programming patterns. It is designed to be more concise than Java.