# Integrating External Spell Checking

## Writer Configuration

In order to enable the spellcheck integration, the Writer's client-config needs to be edited. The following should be added to the client configuration:\
\
Notes:-

· enableSaasSpellcheck should be true in the writer client config

· For the Spellcheck endpoint, by default, the method is POST.  If your API spellcheck endpoint is GET then you need to specifically pass the method as GET&#x20;

· "x-append-authorization": "Bearer Your Token" Add this property in the header if your API needs authentication to run

· For the Suggestion endpoint by default, the method is GET,  if your API suggestion endpoint is POST then you need to specifically pass POST in the method. \
\
**For GET request:**

{% code lineNumbers="true" %}

```javascript
"external": {
         "spellcheck": {
                 "check": {
                     "url": "your-spellcheck-endpoint",
                     "method": "GET",
                     "headers": {
                          "Accept": "application/json; charset=utf-8",
                          "X-Requested-With": "XmlHttpRequest"
                      }
                   },
         "suggestion": {
                "url": "your-suggestion-endpoint",
                "headers": {
                     "Accept": "application/json; charset=utf-8",
                     "X-Requested-With": "XmlHttpRequest"
                      }
                 }
        }
}
```

{% endcode %}

\
**For POST request:**

<pre class="language-javascript" data-line-numbers><code class="lang-javascript">"external": {
        "spellcheck": {
                "check": {
                    "url": "your-spellcheck-endpoint",
                    "headers": {
                          "Accept": "application/json; charset=utf-8",
<strong>                          "X-Requested-With": "XmlHttpRequest"
</strong>                          }
                     },
        "suggestion": {
                  "url": "your-suggestion-endpoint",
                  "method": "POST" ,
                  "headers": {
                        "Accept": "application/json; charset=utf-8",
                        "X-Requested-With": "XmlHttpRequest"
                       }
                }
        }
}
</code></pre>

###

### Field Description

| Field                               | Description                                                                                      |
| ----------------------------------- | ------------------------------------------------------------------------------------------------ |
| `external.spellcheck`               | Contains the configuration for external spellchecking endpoints.                                 |
| `external.spellcheck.check`         | Object containing configuration for external spellcheck requests.                                |
| `external.spellcheck.check.url`     | **Required** Full url and path to your check request implementation.                             |
| `external.spellcheck.check.headers` | **Optional** Key-value object with extra header's which will be used in the request to your API. |
| `external.suggestion`               | Object containing configuration for external suggestion requests.                                |
| `external.suggestion.url`           | **Required** pass suggestions API endpoint                                                       |
| `external.suggestion.headers`       | **Optional** Key-value object with extra header's which will be used in the request to your API. |

The `headers`-properties are useful if you need to send additional headers to your API.

{% hint style="warning" %}
Remember to configure the external spellcheck service to allow cross-origin requests from the writer application url.
{% endhint %}

## External API Specification

Your API needs to be able to handle the following requests to integrate with spell checking and suggestion.

### Language Codes

Language codes from the writer are sent in the format `[language-identifier]_[region_identifier]`. Where `[language-identifier]` follows the [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) standard, which is two letters, lowercased. The `[region-identifier]` follows the [ISO 3166-2](https://en.wikipedia.org/wiki/ISO_3166-2) standard, which is two letters, uppercased.

Examples: `sv_SE`, `en_GB`, `en_US`, `nl_NL`

### Spellcheck Request

The API must be able to receive the following request on an endpoint you define:

#### **Request**

```
    POST [your-spellcheck-endpoint]
    headers
        Accept: application/json
        Content-Type: application/json 
    body
        {
            "lang": "sv_SE",
            "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit"
        }
```

#### **Response**

The API should respond with a single array containing the misspelled words in the same json-format as they were sent, if no words were misspelled, response should contain an empty array.

**Response Format**

```
headers
    Content-Type: application/json 
body
    [
      { "start": 0, "end": 5, "text": "Lorem" },
      { "start": 6, "end": 11, "text": "ipsum" },
      { "start": 12, "end": 17, "text": "dolor" },
      { "start": 61, "end": 63, "text": "do" },
      { "start": 64, "end": 71, "text": "eiusmod" }
    ]
```

**Example Request**

The API should be able to perform the call below, and output an array of the misspelled words, or an empty array.<br>

For making request using GET method:

```javascript
api.router.get('/api/resourceproxy', {

url: `${this.apiURL}?text=${text}&lang=${lang}`,

headers: {

'Content-Type': 'application/json; charset=UTF-8',

...this.extraHeaders

}

})

.then((res) => res.json())

.then((json) => console.log(json))
```

For making request using POST method:

```javascript
api.router.post('/api/resourceproxy', {

url: this.apiURL,

signal: controller.signal,

headers: {

'Content-Type': 'application/json; charset=UTF-8',

...this.extraHeaders

},

body: JSON.stringify({

text,

lang

})

})

.then((res) => res.json())

.then((json) => console.log(json))
```

Output:

```
    [
        {"start":0,"end":5,"text":"Lorem"},
        {"start":6,"end":11,"text":"ipsum"},
        {"start":64,"end":71,"text":"dolor"}
    ]
```

#### Suggestions

The API must be able to receive the following request on an endpoint you define:

**Request**

```
    POST [your-suggestion-endpoint]
    headers
        Accept: application/json
        Content-Type: application/json
    URL Params
        word=String
        lang=[language_code]
```

**Response**

The API should respond with a single array containing the misspelled words in the same json-format as they were sent, if no words were misspelled, response should be an empty array.

**Response Format**

```
    headers
        Content-Type: application/json
    body
        [
            "tempot",
            "tempo",
            "tempon",
            "tempos",
            "teorem"
        ]
```

**Example Request**

The API should be able to perform the call below, and output an array of words, or an empty array.

For making GET request:

```javascript
api.router.get('/api/resourceproxy', {

url: `${externalSpellcheckUrl}?word=${word}&lang=${lang}`,

headers: {

'Content-Type': 'application/json; charset=UTF-8',

...extraHeaders

}

})
```

For making POST request:

```javascript
For making POST request:

api.router.post('/api/resourceproxy', {

url: externalSpellcheckUrl,

headers: {

'Content-Type': 'application/json; charset=UTF-8',

...extraHeaders

},

body: JSON.stringify({

word,

lang

})

})
```

Output

```javascript
["tempo", "temper", "tempos", "temp or", "temp-or", "tempo r"]
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.navigaglobal.com/writer/developer-guide/tutorials/integrating-external-spell-checking.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
