External Executor

External executors are small programs which you run within your own infrastructure to enable connectivity from Xapix Cloud to proprietary or other non-HTTP APIs.

Adding an External Executor

  1. In a project, select Home > Data Sources.

  2. Click Add Data Source and from the dropdown menu, choose External Executor.

  3. Provide a Name for the External executor.

  4. Xapix will generate a URL for you to use in your application to connect to Xapix Cloud. See the example below for how to use this URL in your program.

  5. Apply the URL to your program and start running it.

  6. Add any required parameters.

  7. Click Preview Data Source (you may need to provide values for detected path parameters). You can view the response in the Preview area.

  8. Click Save Data Source.

Click Home > External Executor
Provide a name and copy the URL to your program

External executor example

The following shows an example of a simple python script that increments an input value. This python script has the following features:

  • Request has id (line 25) and callbacks (line 27) fields

  • Response has callback (line 27) and args (line 28) fields

#!/usr/bin/env python
import os
import asyncio
import json
import time
import websockets
endpoint = os.environ.get('XAPIX')
print("Starting incrementer loop... ")
async def executor():
while True:
async with websockets.connect(endpoint) as websocket:
print(f"Connected to {endpoint}... ")
while True:
req = json.loads(await websocket.recv())
print(f"< {req}")
reply = {
'type': 'reply',
'id': req['id'],
'result': 'success',
'response': [{'callback': req['callbacks']['success'],
'args': [req['payload']['value'] + 1]}]
print(f"> {reply}")
await websocket.send(json.dumps(reply))
except websockets.exceptions.ConnectionClosed:
print("Disconnected, reconnecting in 1 second")
except OSError:
print("Connection refused, reconnecting in 1 second")

Using this example python script

Let's use this example python script to demonstrate using an External Executor.

  1. Create a new External Executor as described above and name it something like "my program".

  2. Copy the URL that was generated. In this case it was: wss://executor.xapix.dev/api/v1/register?name=docs-demo/docs-project/my-program-JnMMp0

  3. Open a terminal and create an environment variable. On Windows, use the command: export XAPIX="wss://executor.xapix.dev/api/v1/register?name=docs-demo/docs-project/my-program-JnMMp0"

  4. Test to make sure it was set properly. On Windows use echo $XAPIX.

  5. Copy the script above and save it as test.py.

  6. In the terminal run python test.py.

  7. The program connects to the Xapix endpoint XAPIX (line 9) and waits for requests.

  8. Back in Xapix in the external executor Edit Data Source page for my program, provide a payload parameter called value and set the data sample as, say 10.

  9. Click Preview Data Source. The response should be { "body": 11 }.

  10. Click Save Data Source.

Example script used with the external executor - my program