Sapling Logo
Grammar API quickstart

C Grammar Checker

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

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

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

C does not have a standard HTTP or socket library. HTTP POST requests in C require an HTTP library like libcurl.

#include <stdio.h>
#include <curl/curl.h>

int main(void) {
      char* jsonObj = "{\"key\":\"<API_KEY>\", \"text\":\"Lets get started!\", \"session_id\":\"Test Document UUID\"}";

      struct curl_slist *headers = NULL;
      curl_slist_append(headers, "Accept: application/json");
      curl_slist_append(headers, "Content-Type: application/json");
      curl_slist_append(headers, "charset: utf-8");

      curl_easy_setopt(curl, CURLOPT_URL, "https://api.sapling.ai/api/v1/edits");

      curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT");
      curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
      curl_easy_setopt(curl, CURLOPT_POSTFIELDS, jsonObj);
      curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
      curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);
      curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcrp/0.1");

      res = curl_easy_perform(curl);
}
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 C

The programming language C is well known for its performance and widespread usage across all platforms and systems for multiple decades.