Request & Response

The core configuration of Machine Translation Request

Variables

  • $ID

  • $SOURCE_TEXT

  • $ORIGINAL_TEXT

  • $TRANSLATED_TEXT

  • $SOURCE_LANG

  • $TARGET_LANG

You can use schema variables in the configuration with syntax $SCHEMA_NAME For example:

{
    "schema": [
        { "type": "string", "name": "api_key", "title": "API Key", "default": "", "required": true, "message": "Required an API Key" },
    ],
    "request": {
        "method": "http_post",
        "url": "http://127.0.01/?key=$API_KEY"
        "options": {
            "headers": {
              "Authorization": "Bearer $API_KEY",
              "Content-Type": "application/json"
            }
        }        
    }
}

Parameters

JSON Response from HTTP Request

You can parse the JSON Response with ResponseQuery

The responseQuery is only used for http_get and http_post methods with the response type as JSON

A JSON object is an associative array. The location path syntax to navigate into an arbitrarily deeply nested structure of JSON objects comprises the field names separated by dot '.' delimiters.

For example the following JSON Response

{
  "text": "Hello 1",
  "words": [
    { "text": "Hello 2" },
    { "text": "Hello 3" }
  ]
  "lines": {
    "text": "Hello 4",
    "sub": {
      "text": "Hello 5"
    }        
  }
}
responseQuery
Result

text

Hello 1

words[0].text

Hello 2

lines.sub.text

Hello 5



Examples

1. Web Scraping Method - Object Structure

  • method: string

  • encodeURI: boolean

  • encodeURIComponent: boolean

  • encodeURIExtra: string

  • url: string

  • initialUrl: string

  • querySelector: string

  • querySelectorAll: string

  • queryProperty: string

{
    "request": {
        "method": "web_scraping",
        "encodeURI": false,
        "encodeURIComponent": true, 
        "initialUrl": "https://localhost:8080",
        "url": "https://localhost:8080/?sl=$SOURCE_LANG&tl=$TARGET_LANG&text=$SOURCE_TEXT",    
        "querySelector": "span[lang=$TARGET_LANG]",
        "querySelectorAll": null,                
        "queryProperty": "innerText"
    }
}

2. HTTP GET Method- Object Structure

  • method: string

  • encodeURI: boolean

  • encodeURIComponent: boolean

  • encodeURIExtra: string

  • url: string

  • options: object

  • responseType: string

  • responseQuery: string

{
    "request": {
        "method": "http_get",
        "encodeURI": false,
        "encodeURIComponent": false, 
        "url": "https://localhost:8080/translate?sl=$SOURCE_LANG&tl=$TARGET_LANG&text=$SOURCE_TEXT",
        "options": {},
        "responseType": "string"  
    }
}

3. HTTP POST Method - Object Structure

  • method: string

  • encodeURI: boolean

  • encodeURIComponent: boolean

  • encodeURIExtra: string

  • url: string

  • body: object

  • options: object

    • headers: object

      • X-Custom-Header: string

      • Authorization: string

      • Content-Type: string

  • responseType: string

  • responseQuery: string

{
    "request": {
        "method": "http_post",
        "encodeURI": false,
        "encodeURIComponent": false, 
        "url": "https://localhost:8080/translate",
        "body": {
            "text": "$SOURCE_TEXT",
            "source_lang": "$SOURCE_LANG",
            "target_lang": "$TARGET_LANG"
        }
        "options": {
            "headers": {
                "Authorization": "Bearer $API_KEY",
                "Content-Type": "application/json"
            }
        },
        "responseType": "json",
        "responseQuery": "translate.result"
    }
}

Last updated