Integrating External Spell Checking

It is possible to create your own Web API endpoints and integrate your own spell checking and suggestions into the Writer.

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

· "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:

"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"
                      }
                 }
        }
}

For POST request:

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

Field Description

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

Remember to configure the external spellcheck service to allow cross-origin requests from the writer application url.

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 standard, which is two letters, lowercased. The [region-identifier] follows the 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.

For making request using GET method:

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:

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:

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

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

headers: {

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

...extraHeaders

}

})

For making POST request:

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

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