Sapling Logo
Grammar API quickstart

Go Grammar Checker

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

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

Go 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.
Go /api/v1/edits
import (
  "bytes"
  "encoding/json"
  "fmt"
  "io/ioutil"
  "net/http"
)

func main() {
  postBody, _ := json.Marshal(map[string]string{
    "key":  "<API_KEY>",
    "text": "Lets get started",
    "session_id": "Test Document UUID",
  })
  responseBody := bytes.NewBuffer(postBody)
  resp, err := http.Post("https://api.sapling.ai/api/v1/edits", "application/json", responseBody)

  if err != nil {
    fmt.Println("An Error Occured %v", err)
  }
  defer resp.Body.Close()
  body, err := ioutil.ReadAll(resp.Body)
  if err != nil {
    fmt.Println(err)
  }
  sb := string(body)
  fmt.Println(sb)
}
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 Go

Go is a programming language designed at Google, to have performance similarity to C but with easier readability, memory safety, garbage collection and easier concurrency.