Skip to main content

Running Functions

In this document we will invoke a function that we created here. Full code can be found on Github

Invoking a function

After a function has been deployed, you can invoke it using cape run and specifying either the function name or ID:

cape run capedocs/isprime 13

Which produces:

13 is prime

Feel free to experiment with numbers other than 13.

Note: In this example, the function capedocs/isprime is a combination of the user (Github handle) and function name. You can also refer to a function by it's ID.

Additionally, there are example functions for sentiment analysis and image recognition that you can experiment with. Full code examples for more sample functions can be found on Github.

Parameters

cape run accepts a function ID (or name) and the function input data as parameters.

The function ID is provided by the Cape CLI when you deploy your function. You can optionally choose to name your function as well using the flag --name during deployment.

Input data will be specific to your function, and is passed as bytes. Your function is tasked with handling the input appropriately, allowing for maximum flexibility for function developers.

Note: Use the -f flag to pass input data as a file.

SDKs

Now that you've seen how you can run a function in a CLI, you can use one of our SDKs to integrate Cape into your app.

Here’s a quick example of encrypting data and running a function in JavaScript:

const data = await cape.encrypt("Hello World");
const result = await cape.run({ id: "capedocs/sentiment", data });
console.log(result);

Which produces: ​

92.88% positive

Or a similar example in Python:

encryptedData = cape.encrypt('Hello World')
result = cape.run( 'sentiment-analysis', encryptedData)
print(result)

Which produces: ​

92.88% positive

Checkout the cape-js and pycape on GitHub for complete examples.