Skip to content

Example: Language Translation

Owen Swerkstrom edited this page Jul 13, 2015 · 15 revisions

The manifest for a language translation Motion service might look like so:

{
    “name”: “translate”,
    “description”: “Translates a message from one language to another”,
    “requires”: [ “subject”, “body” ],
    “modifies”: [ “subject”, “body”, “language” ],
    “configurable”: true,
    “endpoint”: “https://translate.example.com/translate/”
}

Note that this service has "configurable": true. That means that if we then POST a blank document to it, the service will create a new configuration instance, and serve up a human-interactive page with which may be used to select the desired configuration settings. The mechanisms used to store these settings within the service are not defined by Motion; we care only that we now have a path at which our settings may be changed and to which we will POST our messages to be processed.

C:POST /translate/translate/ HTTP/1.1
C:Content-Length: 0
C:
S:HTTP/1.1 201 Created
S:Location: /translate/options/a1e9
S:

We may now POST the required fields from our message data to the service, and receive the translated versions.

C:POST /translate/options/a1e9 HTTP/1.1
C:Content-Type: application/json
C:
C:{
C:    “subject”: “Bonjour!”,
C:    “body”: {
C:        “text”: “j'oublie tout”,
C:        “html”: “<html><body>j'oub...
C:    }
C:}
C:
S:HTTP/1.1 200 Ok
S:Content-Type: application/json
S:
S:{
S:    “language”: “en”,
S:    “subject”: “Hello!”,
S:    “body”: {
S:        “text”: “I forget everything”,
S:        “html”: “<html><body>I forg...
S:    }
S:}
Clone this wiki locally