A sample JavaScript function that multiplies a number by itself, returning the squared value.
-
Install riff.
These instructions assume riff v0.2.0 or later. See riff's Getting Started guide. Skip if you already have riff running.
-
Create the function.
This assumes that the default namespace was initialized with credentials for your
DOCKER_ID
on Docker Hub.riff function create square \ --git-repo https://github.com/projectriff-samples/node-square \ --artifact square.js \ --image $DOCKER_ID/square \ --verbose
-
Invoke the function.
riff service invoke square --json -- -w '\n' -d 7
Result:
curl http://localhost:31380/ -H 'Host: square.default.example.com' -H 'Content-Type: application/json' -w '\n' -d 7 49
Change the number 7 to another number to see its square.