Sapling Logo
Grammar API quickstart

Perl Grammar Checker

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

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

Perl 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.
Perl /api/v1/edits
use Encode qw(encode_utf8);
use HTTP::Request ();
use JSON::MaybeXS qw(encode_json);
use MIME::Base64;


my $url = 'https://testapi.com/webapi/AddData';
my $header = ['Content-Type' => 'application/json; charset=UTF-8'];
my $data = {key=> 'API_KEY', text=> 'Lets get started', 'session_id' => "Test Document UUID"};
my $encoded_data = encode_utf8(encode_json($data));
my $r = HTTP::Request->new('POST', $url, $header, $encoded_data);
print $r->responseContent();
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 Perl

Perl is a family of high-level interpreted scripting languages, including Perl 5 and Perl 6, which was renamed to Raku. It is popular as a scripting language because of its built-in regular expression and string parsing functionality.