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.
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);
}
{
"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++
C++ is an object-oriented programming language that provides a superset of features of C. It is a popular choice for large programming projects that require the performance characteristics of C but want code organized as classes. Cross-platform applications developed with the Qt framework typically are written in C++.