Sapling Logo
Grammar API quickstart

JavaScript Grammar Checker

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

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

JavaScript 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.
JavaScript /api/v1/edits

HTML / JavaScript

<script src="https://sapling.ai/static/js/sapling-sdk-v1.1.1.min.js"></script>

<div contenteditable="true" id="check-space" sapling-ignore="true">Lets get started!</div>

<script type="text/javascript">
Sapling.init({
  key: '<API_KEY>',
  endpointHostname: 'https://api.sapling.ai',
  editPathname: '/api/v1/edits',
  statusBadge: true,
  mode: 'dev',
});

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

Node.js / JavaScript

  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 JavaScript

JavaScript is a scripting language used in browsers to provide client-side dynamic application behavior. Almost all websites use it. Additionally, JavaScript is also used in server-side applications through environments like Node.js. Cross-platform and desktop applications can be developed using the Electron framework.