Sapling Logo
Grammar API quickstart

TypeScript Grammar Checker

Add spelling and grammar suggestions to a TypeScript application with Sapling's edits API.

  • HTTPS POST
  • SDK + HTTP
  • API key required
POST TypeScript logo TypeScript /api/v1/edits

TypeScript 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.

Sapling provides an SDK for this stack. The direct HTTP example below remains useful for server-side integrations; see the SDK overview for the higher-level client.
TypeScript /api/v1/edits

HTML / TypeScript

<script src="https://sapling.ai/static/js/sapling-sdk-v1.1.1.min.js"></script>
<div contenteditable="true" id="check-space"></div>

<script type="text/javascript">
Sapling.init({
  endpointHostname: "https://api.sapling.ai",
  editPathname: "/api/edits",
  completePathname: "/api/complete",
  autocomplete: true,
  statusBadge: true,
});

const contentEditable = document.getElementById('check-space');
Sapling.observe(contentEditable);
</script>

Node.js / TypeScript

  npm install saplingai/sapling-js
import { Client } from "@saplingai/sapling-js/client";

const apiKey = '<API_KEY>';
const client = new Client(apiKey);
client
  .edits('Lets get started!')
  .then(function (response) {
    console.log(response.data);
  })
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 TypeScript

TypeScript is a strongly-typed programming language that transpiles into JavaScript. It is a superset or extension of JavaScript and adds optional static typing functionality. The language is developed and maintained by Microsoft.