From a2c0950d7153c1f3fb35529a399ac95cac2ead4f Mon Sep 17 00:00:00 2001 From: Jiaxin Fan Date: Mon, 31 Oct 2022 14:20:37 +0100 Subject: [PATCH 1/6] Restore missing documentation about how to test runtimes standalone. Revised README, also add EOL at end of file Attempt to fix trailing white space Checked for typos Fix minor formatting error, test Git still works WIP: update top-level README --- README.md | 1 + tests/src/test/standalone/README.md | 89 +++++++++++++++++++ .../standalone/helloworld/helloworld.json | 8 ++ 3 files changed, 98 insertions(+) create mode 100644 tests/src/test/standalone/README.md create mode 100644 tests/src/test/standalone/helloworld/helloworld.json diff --git a/README.md b/README.md index 09c936a2..9dd20bec 100644 --- a/README.md +++ b/README.md @@ -114,3 +114,4 @@ This will return the following runtime images with the following names: `action- ``` ./gradlew :tests:test ``` +An update about the details of verifying a standalone container can be found [here](https://github.com/apache/openwhisk-runtime-nodejs/pull/227/files#diff-c115bfeccd5f4a2e984d66e08ad3b677350baecacc248bc20d7585c2b6fe11e8) diff --git a/tests/src/test/standalone/README.md b/tests/src/test/standalone/README.md new file mode 100644 index 00000000..e1424adf --- /dev/null +++ b/tests/src/test/standalone/README.md @@ -0,0 +1,89 @@ + + +# Tests for OpenWhisk NodeJS Runtime as Standalone Container +## Building the Runtime Container +After a runtime container is built, one should be able to run it as a standalone container. +The following example shows how to generate a Docker image for the Node.js 18 runtime version and test the standalone runtime using the `curl` command. Testing other runtime versions can be done in the same manner. + +- Run the `distDocker` command to generate the local Docker image for the desired runtime version. +``` +./gradlew core:nodejs18Action:distDocker +``` +This will return the following runtime image with the name `action-nodejs-v18`, which should be listed after using the `docker images` + +## Running the Container +For the purpose of the test. We are going to start the container that has a web service running inside it built using Node/Express. In order to access this service within the container from the outside, as we are about to do using `curl`, port mapping needs to be done next. As a result, we can now access the web service inside docker by first reaching an IP port on `localhost`, which subsequently forwards the request to the docker container's designated port. +In our example, the `Action` container exposes `port 8080` (see the Dockerfile for the associated Docker image), thus we publish the container's `port 8080` to the `localhost` (here, `port 3008` on `localhost` is chosen arbitrarily, as long as the port is not already assigned for something else): +``` +docker run --publish 3008:8080 -i -t action-nodejs-v18:latest +``` +A simpler way is to map `port 80` on `localhost` to the container's `port 8080`. The port number assigned to the HTTP protocol is `80` Since we will be sending actions against the runtime using HTTP, using this number will allow us to omit the port in the request later. Without loss of generality, the following examples will use the arbitrarily chosen `port 3008` + +## Testing +This example has prepared a `helloworld.json` file to post using `curl`. +```json +{ + "value": { + "name" : "nodejs-helloworld", + "main" : "main", + "binary": false, + "code" : "function main() {return {payload: 'Hello World!'};}" + } +} +``` +The json file contains a simple JavaScript function, which is the actual payload. + +### Initialze the Runtime +Before issuing the action against the runtime, we first initialize the function with by invoking the ```/init``` endpoint. +``` +curl -H "Content-Type:application/json" -X POST --data '@openwhisk-runtime-nodejs/tests/src/test/standalone/helloworld/helloworld.json' http://localhost:3008/init + +{"OK":true} +``` +being the expected response. + +As mentioned above, if `port 80` on `localhost` was used, the command could simply be +``` +curl -H "Content-Type:application/json" -X POST --data '@openwhisk-runtime-nodejs/tests/src/test/standalone/helloworld/helloworld.json' http://localhost/init +``` + +#### Run the function + +Invoke the function using the ```/run``` endpoint. + +``` +curl -H ""Content-Type:application/json" -X POST --data '@openwhisk-runtime-nodejs/tests/src/test/standalone/helloworld/helloworld.json' http://localhost:3008/run +``` + +The JavaScript function in this example is one without arguments. Using the same json file as during initialization won't be a problem. Strictly speaking, we should have provided another json file with the arguments. In our case, it should simply be +```json +{ + "value": {} +} +``` +The expected response should be +``` +{"payload":"Hello World!"} +``` +Also the running container will print +``` +XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX +``` +in the terminal diff --git a/tests/src/test/standalone/helloworld/helloworld.json b/tests/src/test/standalone/helloworld/helloworld.json new file mode 100644 index 00000000..8bb442b8 --- /dev/null +++ b/tests/src/test/standalone/helloworld/helloworld.json @@ -0,0 +1,8 @@ +{ + "value": { + "name" : "nodejs-helloworld", + "main" : "main", + "binary": false, + "code" : "function main() {return {payload: 'Hello World!'};}" + } +} \ No newline at end of file From 833375c10b035cdabe5d67092e5f28519b263b13 Mon Sep 17 00:00:00 2001 From: Jiaxin Fan Date: Fri, 30 Dec 2022 15:11:01 +0100 Subject: [PATCH 2/6] Relocate to doc/user dir --- README.md | 2 +- {tests/src/test => docs/users}/standalone/README.md | 0 .../test => docs/users}/standalone/helloworld/helloworld.json | 0 3 files changed, 1 insertion(+), 1 deletion(-) rename {tests/src/test => docs/users}/standalone/README.md (100%) rename {tests/src/test => docs/users}/standalone/helloworld/helloworld.json (100%) diff --git a/README.md b/README.md index 9dd20bec..37d76b7e 100644 --- a/README.md +++ b/README.md @@ -114,4 +114,4 @@ This will return the following runtime images with the following names: `action- ``` ./gradlew :tests:test ``` -An update about the details of verifying a standalone container can be found [here](https://github.com/apache/openwhisk-runtime-nodejs/pull/227/files#diff-c115bfeccd5f4a2e984d66e08ad3b677350baecacc248bc20d7585c2b6fe11e8) +An update about the details of verifying a standalone container can be found [here](https://github.com/apache/openwhisk-runtime-nodejs/tree/master/docs/users) diff --git a/tests/src/test/standalone/README.md b/docs/users/standalone/README.md similarity index 100% rename from tests/src/test/standalone/README.md rename to docs/users/standalone/README.md diff --git a/tests/src/test/standalone/helloworld/helloworld.json b/docs/users/standalone/helloworld/helloworld.json similarity index 100% rename from tests/src/test/standalone/helloworld/helloworld.json rename to docs/users/standalone/helloworld/helloworld.json From 5a2ae2002cdb0b51ade53d519c71d12f0c8f8167 Mon Sep 17 00:00:00 2001 From: Jiaxin Fan Date: Mon, 30 Jan 2023 17:08:03 +0100 Subject: [PATCH 3/6] Explain Gradle and add one use case --- docs/users/standalone/README.md | 131 ++++++++++++++++++++++++++------ 1 file changed, 109 insertions(+), 22 deletions(-) diff --git a/docs/users/standalone/README.md b/docs/users/standalone/README.md index e1424adf..959a26f4 100644 --- a/docs/users/standalone/README.md +++ b/docs/users/standalone/README.md @@ -18,26 +18,59 @@ --> # Tests for OpenWhisk NodeJS Runtime as Standalone Container +[![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0) + +This README walks you through how to build, customise and test Apache OpenWhisk Node.js runtime images. +## Pre-requisites +- [Gradle](https://gradle.org/) +- [Docker](https://www.docker.com/) +- [curl](https://curl.se/) ## Building the Runtime Container -After a runtime container is built, one should be able to run it as a standalone container. -The following example shows how to generate a Docker image for the Node.js 18 runtime version and test the standalone runtime using the `curl` command. Testing other runtime versions can be done in the same manner. +Choose a NodeJS version. All build files reside inside `core/nodejsActionBase`. If you take a look into `core/nodejsActionBase/Dockerfile` you’ll see a line that looks like: +``` +FROM node:lts-stretch +``` +This will use the latest NodeJS version. But we want to be more specific. Now if you look into each of the Dockerfile within `core/nodejs14Action`, `core/nodejs16Action`, `core/nodejs18Action`, you’ll notice different NodeJS versions. Let’s go ahead with the 18 version. We are going to use this version throughout the README, for the others, you merely have to modify the version number. + +Gradle will a create `build` folder that will contain all the necessary files to build our NodeJS container. Next, it will copy the NodeJS application (server used to implement the [action interface](https://github.com/apache/openwhisk/blob/master/docs/actions-new.md#action-interface)) as well as the target Dockerfile with the NodeJS version 18. + +What Gradle does is equivalent to running these commands +``` +mkdir build +cp -r core/nodejsActionBase/* build +cp core/nodejs18Action/Dockerfile build +``` + +Now, run the `distDocker` command to generate a local Docker image for the chosen runtime version. (Make sure docker daemon is running) -- Run the `distDocker` command to generate the local Docker image for the desired runtime version. ``` ./gradlew core:nodejs18Action:distDocker ``` -This will return the following runtime image with the name `action-nodejs-v18`, which should be listed after using the `docker images` +This will return the following runtime image with the name `action-nodejs-v18`. Since a docker image is created, you can check the `IMAGE ID` for `nodejs-action-v18` +``` +docker images +``` ## Running the Container -For the purpose of the test. We are going to start the container that has a web service running inside it built using Node/Express. In order to access this service within the container from the outside, as we are about to do using `curl`, port mapping needs to be done next. As a result, we can now access the web service inside docker by first reaching an IP port on `localhost`, which subsequently forwards the request to the docker container's designated port. -In our example, the `Action` container exposes `port 8080` (see the Dockerfile for the associated Docker image), thus we publish the container's `port 8080` to the `localhost` (here, `port 3008` on `localhost` is chosen arbitrarily, as long as the port is not already assigned for something else): +For the testing purpose, we are going to start the container locally that has Node.js app server inside. The Apache OpenWhisk platform uses this server to inject action code into the runtime and fire invocation requests. In order to access this service within the container from the outside, as we are about to do using `curl`, port mapping needs to be done next. As a result, we can now access the web service inside docker by first reaching an IP port on `localhost`, which subsequently forwards the request to the docker container's designated port. +In our example, the `Action` container exposes `port 8080` (see the Dockerfile for the associated Docker image), thus we publish the container's `port 8080` to the `localhost` (here, `port 3008` on `localhost` is chosen arbitrarily, as long as the port is not already used for something else): ``` -docker run --publish 3008:8080 -i -t action-nodejs-v18:latest +docker run --publish 3008:8080 --name=bloom_whisker -i -t action-nodejs-v18:latest ``` -A simpler way is to map `port 80` on `localhost` to the container's `port 8080`. The port number assigned to the HTTP protocol is `80` Since we will be sending actions against the runtime using HTTP, using this number will allow us to omit the port in the request later. Without loss of generality, the following examples will use the arbitrarily chosen `port 3008` +A simpler way is to map `port 80 ` on `localhost ` to the container's `port 8080`. The port number assigned to the HTTP protocol is `80`. Since we will be sending actions against the runtime using HTTP, using this number will allow us to omit the port in the request later. Oftentimes, `port 80 ` could already be occupied by another process. Without loss of generality, the following examples will use the arbitrarily chosen `port 3008`. -## Testing -This example has prepared a `helloworld.json` file to post using `curl`. +Lists all running containers +``` +docker ps +``` +or +``` +docker ps -a +``` +You should see a container named `bloom_whisker` being run. + +## Create your function +A container can only hold one function. This first example prepared a `js-init.json` file which contains the function. ```json { "value": { @@ -48,42 +81,96 @@ This example has prepared a `helloworld.json` file to post using `curl`. } } ``` -The json file contains a simple JavaScript function, which is the actual payload. +The json file contains a simple JavaScript (the target runtime language) function, which is the actual payload. -### Initialze the Runtime +## Initialze the Runtime Before issuing the action against the runtime, we first initialize the function with by invoking the ```/init``` endpoint. ``` -curl -H "Content-Type:application/json" -X POST --data '@openwhisk-runtime-nodejs/tests/src/test/standalone/helloworld/helloworld.json' http://localhost:3008/init - -{"OK":true} +curl -H "Content-Type:application/json" -X POST --data '@/$FILEPATH/js-init.json' http://localhost:3008/init +``` +the expected response being +``` +{"ok":true} ``` -being the expected response. As mentioned above, if `port 80` on `localhost` was used, the command could simply be ``` -curl -H "Content-Type:application/json" -X POST --data '@openwhisk-runtime-nodejs/tests/src/test/standalone/helloworld/helloworld.json' http://localhost/init +curl -H "Content-Type:application/json" -X POST --data '@/$FILEPATH/js-init.json' http://localhost/init ``` -#### Run the function +## Run the function Invoke the function using the ```/run``` endpoint. ``` -curl -H ""Content-Type:application/json" -X POST --data '@openwhisk-runtime-nodejs/tests/src/test/standalone/helloworld/helloworld.json' http://localhost:3008/run +curl -H ""Content-Type:application/json" -X POST --data '@/$FILEPATH/js-init.json' http://localhost:3008/run ``` -The JavaScript function in this example is one without arguments. Using the same json file as during initialization won't be a problem. Strictly speaking, we should have provided another json file with the arguments. In our case, it should simply be +The JavaScript function in this example is one without arguments (nullary function). Using the same json file as during initialization won't be a problem. Ideally, we should have provided another file `js-params.json` with the arguments to trigger the function. ```json { "value": {} } ``` +In this case the command to trigger the function should be +``` +curl -H ""Content-Type:application/json" -X POST --data '/$FILEPATH/js-params.json' http://localhost:3008/run +``` + The expected response should be ``` {"payload":"Hello World!"} ``` -Also the running container will print +Also the running container will print the following message in the terminal +``` +XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX +``` + +## Functions with arguments +If your container still running from the previous example you must stop it before proceeding. Because each NodeJS runtime can only hold one function which cannot be overridden. + +Create a file called `js-init-params.json` that contains the function to be initialized +```json +{ + "value": { + "name": "js-helloworld-with-params", + "main" : "main", + "binary" : false, + "code" : "function main(params) { return {payload: 'Hello ' + params.name + ' from ' + params.place + '!!!'} }" + } +} +``` + +Also, create a file called `js-run-params.json` which contains the parameters for triggering the function. +```json +{ + "value": { + "name": "Visitor", + "place": "Earth" + } +} +``` +These files shall be sent via the `init` API and via the `run` API respectively. + +To initialize the function, please make sure your NodeJS runtime container is running. +First, issue a `POST` request against the `init` API using curl: +``` +curl -H "Content-Type:application/json" -X POST --data '@/$FILEPATH/js-init-params.json' http://localhost:3008/init +``` + +Next, trigger the function by issuing this request against the `run` API using curl: +``` +curl -H ""Content-Type:application/json" -X POST --data '/$FILEPATH/js-run-params.json' http://localhost:3008/run +``` + +You should expect the following client response: +``` +{"payload": "Hello Visitor from Earth!!!"} +``` + +And this response from the container: ``` XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX ``` -in the terminal + +## Thanks for following along! From c3c8503bcab023b29d9705837234e5e28b5d3c19 Mon Sep 17 00:00:00 2001 From: Jiaxin Fan Date: Mon, 30 Jan 2023 17:16:52 +0100 Subject: [PATCH 4/6] Add example json files Add CI status Rebase resolved Squash commits Update top level README Rollback changes to ci.yaml --- README.md | 4 ++-- docs/users/standalone/README.md | 4 +--- .../helloworld/{helloworld.json => js-init.json} | 0 docs/users/standalone/helloworld/js-params.json | 3 +++ .../standalone/helloworldwithparams/js-init-params.json | 8 ++++++++ .../standalone/helloworldwithparams/js-run-params.json | 6 ++++++ 6 files changed, 20 insertions(+), 5 deletions(-) rename docs/users/standalone/helloworld/{helloworld.json => js-init.json} (100%) create mode 100644 docs/users/standalone/helloworld/js-params.json create mode 100644 docs/users/standalone/helloworldwithparams/js-init-params.json create mode 100644 docs/users/standalone/helloworldwithparams/js-run-params.json diff --git a/README.md b/README.md index 37d76b7e..13a05f13 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,7 @@ The `core/nodejsActionBase` folder contains the Node.js app server used to imple This will return the following runtime images with the following names: `action-nodejs-v14`, `action-nodejs-v16`, and `action-nodejs-v18`. ### Testing +( A new section on building and testing the standalone runtime container is available here. ) - Install project dependencies from the top-level Apache OpenWhisk [project](https://github.com/apache/openwhisk), which ensures correct versions of dependent libraries are available in the Maven cache. @@ -113,5 +114,4 @@ This will return the following runtime images with the following names: `action- ``` ./gradlew :tests:test -``` -An update about the details of verifying a standalone container can be found [here](https://github.com/apache/openwhisk-runtime-nodejs/tree/master/docs/users) +``` \ No newline at end of file diff --git a/docs/users/standalone/README.md b/docs/users/standalone/README.md index 959a26f4..b455bb5d 100644 --- a/docs/users/standalone/README.md +++ b/docs/users/standalone/README.md @@ -18,8 +18,6 @@ --> # Tests for OpenWhisk NodeJS Runtime as Standalone Container -[![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0) - This README walks you through how to build, customise and test Apache OpenWhisk Node.js runtime images. ## Pre-requisites - [Gradle](https://gradle.org/) @@ -57,7 +55,7 @@ In our example, the `Action` container exposes `port 8080` (see the Dockerfile f ``` docker run --publish 3008:8080 --name=bloom_whisker -i -t action-nodejs-v18:latest ``` -A simpler way is to map `port 80 ` on `localhost ` to the container's `port 8080`. The port number assigned to the HTTP protocol is `80`. Since we will be sending actions against the runtime using HTTP, using this number will allow us to omit the port in the request later. Oftentimes, `port 80 ` could already be occupied by another process. Without loss of generality, the following examples will use the arbitrarily chosen `port 3008`. +A simpler way is to map `port 80` on `localhost` to the container's `port 8080`. The port number assigned to the HTTP protocol is `80`. Since we will be sending actions against the runtime using HTTP, using this number will allow us to omit the port in the request later. Oftentimes, `port 80` could already be occupied by another process. Without loss of generality, the following examples will use the arbitrarily chosen `port 3008`. Lists all running containers ``` diff --git a/docs/users/standalone/helloworld/helloworld.json b/docs/users/standalone/helloworld/js-init.json similarity index 100% rename from docs/users/standalone/helloworld/helloworld.json rename to docs/users/standalone/helloworld/js-init.json diff --git a/docs/users/standalone/helloworld/js-params.json b/docs/users/standalone/helloworld/js-params.json new file mode 100644 index 00000000..0efca278 --- /dev/null +++ b/docs/users/standalone/helloworld/js-params.json @@ -0,0 +1,3 @@ +{ + "value": { } + } \ No newline at end of file diff --git a/docs/users/standalone/helloworldwithparams/js-init-params.json b/docs/users/standalone/helloworldwithparams/js-init-params.json new file mode 100644 index 00000000..a877f7b9 --- /dev/null +++ b/docs/users/standalone/helloworldwithparams/js-init-params.json @@ -0,0 +1,8 @@ +{ + "value": { + "name": "js-helloworld-with-params", + "main" : "main", + "binary" : false, + "code" : "function main(params) { return {payload: 'Hello ' + params.name + ' from ' + params.place + '!!!'} }" + } + } \ No newline at end of file diff --git a/docs/users/standalone/helloworldwithparams/js-run-params.json b/docs/users/standalone/helloworldwithparams/js-run-params.json new file mode 100644 index 00000000..8e1c886c --- /dev/null +++ b/docs/users/standalone/helloworldwithparams/js-run-params.json @@ -0,0 +1,6 @@ +{ + "value": { + "name": "Visitor", + "place": "Earth" + } + } \ No newline at end of file From 2e40767381876fae868ff852f7abd29ab2c19fde Mon Sep 17 00:00:00 2001 From: Jiaxin Fan Date: Thu, 2 Feb 2023 17:33:45 +0100 Subject: [PATCH 5/6] Fix EOL scan add EOL Fix filepath in curl command --- README.md | 2 +- docs/{users => }/standalone/README.md | 16 ++++++++-------- .../standalone/helloworld/js-init.json | 2 +- .../standalone/helloworld/js-params.json | 2 +- .../helloworldwithparams/js-init-params.json | 2 +- .../helloworldwithparams/js-run-params.json | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) rename docs/{users => }/standalone/README.md (84%) rename docs/{users => }/standalone/helloworld/js-init.json (98%) rename docs/{users => }/standalone/helloworld/js-params.json (86%) rename docs/{users => }/standalone/helloworldwithparams/js-init-params.json (99%) rename docs/{users => }/standalone/helloworldwithparams/js-run-params.json (97%) diff --git a/README.md b/README.md index 13a05f13..8422fce6 100644 --- a/README.md +++ b/README.md @@ -114,4 +114,4 @@ This will return the following runtime images with the following names: `action- ``` ./gradlew :tests:test -``` \ No newline at end of file +``` diff --git a/docs/users/standalone/README.md b/docs/standalone/README.md similarity index 84% rename from docs/users/standalone/README.md rename to docs/standalone/README.md index b455bb5d..8cc41a4b 100644 --- a/docs/users/standalone/README.md +++ b/docs/standalone/README.md @@ -28,9 +28,9 @@ Choose a NodeJS version. All build files reside inside `core/nodejsActionBase`. ``` FROM node:lts-stretch ``` -This will use the latest NodeJS version. But we want to be more specific. Now if you look into each of the Dockerfile within `core/nodejs14Action`, `core/nodejs16Action`, `core/nodejs18Action`, you’ll notice different NodeJS versions. Let’s go ahead with the 18 version. We are going to use this version throughout the README, for the others, you merely have to modify the version number. +This will use the latest NodeJS version. But we want to be more specific. Now if you look into each of the Dockerfile within `core/nodejs14Action`, `core/nodejs16Action`, `core/nodejs18Action`, you’ll notice different NodeJS versions. Let’s go ahead with the 18 version, we are going to use this throughout this README. For the other versions, you merely have to modify the version number. -Gradle will a create `build` folder that will contain all the necessary files to build our NodeJS container. Next, it will copy the NodeJS application (server used to implement the [action interface](https://github.com/apache/openwhisk/blob/master/docs/actions-new.md#action-interface)) as well as the target Dockerfile with the NodeJS version 18. +Gradle will a create `build` folder that will contain all the necessary files to build our NodeJS container. Next, it will copy the NodeJS application ( server used to implement the [action interface](https://github.com/apache/openwhisk/blob/master/docs/actions-new.md#action-interface) ) as well as the target Dockerfile with the NodeJS version 18. What Gradle does is equivalent to running these commands ``` @@ -84,7 +84,7 @@ The json file contains a simple JavaScript (the target runtime language) functio ## Initialze the Runtime Before issuing the action against the runtime, we first initialize the function with by invoking the ```/init``` endpoint. ``` -curl -H "Content-Type:application/json" -X POST --data '@/$FILEPATH/js-init.json' http://localhost:3008/init +curl -H "Content-Type:application/json" -X POST --data '@/docs/users/standalone/helloworld/js-init.json' http://localhost:3008/init ``` the expected response being ``` @@ -93,7 +93,7 @@ the expected response being As mentioned above, if `port 80` on `localhost` was used, the command could simply be ``` -curl -H "Content-Type:application/json" -X POST --data '@/$FILEPATH/js-init.json' http://localhost/init +curl -H "Content-Type:application/json" -X POST --data '@/docs/users/standalone/helloworld/js-init.json' http://localhost/init ``` ## Run the function @@ -101,7 +101,7 @@ curl -H "Content-Type:application/json" -X POST --data '@/$FILEPATH/js-init.json Invoke the function using the ```/run``` endpoint. ``` -curl -H ""Content-Type:application/json" -X POST --data '@/$FILEPATH/js-init.json' http://localhost:3008/run +curl -H ""Content-Type:application/json" -X POST --data '@//docs/users/standalone/helloworld/js-init.json' http://localhost:3008/run ``` The JavaScript function in this example is one without arguments (nullary function). Using the same json file as during initialization won't be a problem. Ideally, we should have provided another file `js-params.json` with the arguments to trigger the function. @@ -112,7 +112,7 @@ The JavaScript function in this example is one without arguments (nullary functi ``` In this case the command to trigger the function should be ``` -curl -H ""Content-Type:application/json" -X POST --data '/$FILEPATH/js-params.json' http://localhost:3008/run +curl -H ""Content-Type:application/json" -X POST --data '@/docs/users/standalone/helloworld/js-params.json' http://localhost:3008/run ``` The expected response should be @@ -153,12 +153,12 @@ These files shall be sent via the `init` API and via the `run` API respectively. To initialize the function, please make sure your NodeJS runtime container is running. First, issue a `POST` request against the `init` API using curl: ``` -curl -H "Content-Type:application/json" -X POST --data '@/$FILEPATH/js-init-params.json' http://localhost:3008/init +curl -H "Content-Type:application/json" -X POST --data '@/docs/users/standalone/helloworldwithparams/js-init-params.json' http://localhost:3008/init ``` Next, trigger the function by issuing this request against the `run` API using curl: ``` -curl -H ""Content-Type:application/json" -X POST --data '/$FILEPATH/js-run-params.json' http://localhost:3008/run +curl -H ""Content-Type:application/json" -X POST --data '@/docs/users/standalone/helloworldwithparams/js-run-params.json' http://localhost:3008/run ``` You should expect the following client response: diff --git a/docs/users/standalone/helloworld/js-init.json b/docs/standalone/helloworld/js-init.json similarity index 98% rename from docs/users/standalone/helloworld/js-init.json rename to docs/standalone/helloworld/js-init.json index 8bb442b8..951330cf 100644 --- a/docs/users/standalone/helloworld/js-init.json +++ b/docs/standalone/helloworld/js-init.json @@ -5,4 +5,4 @@ "binary": false, "code" : "function main() {return {payload: 'Hello World!'};}" } -} \ No newline at end of file +} diff --git a/docs/users/standalone/helloworld/js-params.json b/docs/standalone/helloworld/js-params.json similarity index 86% rename from docs/users/standalone/helloworld/js-params.json rename to docs/standalone/helloworld/js-params.json index 0efca278..2572ae6b 100644 --- a/docs/users/standalone/helloworld/js-params.json +++ b/docs/standalone/helloworld/js-params.json @@ -1,3 +1,3 @@ { "value": { } - } \ No newline at end of file +} diff --git a/docs/users/standalone/helloworldwithparams/js-init-params.json b/docs/standalone/helloworldwithparams/js-init-params.json similarity index 99% rename from docs/users/standalone/helloworldwithparams/js-init-params.json rename to docs/standalone/helloworldwithparams/js-init-params.json index a877f7b9..c4018113 100644 --- a/docs/users/standalone/helloworldwithparams/js-init-params.json +++ b/docs/standalone/helloworldwithparams/js-init-params.json @@ -5,4 +5,4 @@ "binary" : false, "code" : "function main(params) { return {payload: 'Hello ' + params.name + ' from ' + params.place + '!!!'} }" } - } \ No newline at end of file +} diff --git a/docs/users/standalone/helloworldwithparams/js-run-params.json b/docs/standalone/helloworldwithparams/js-run-params.json similarity index 97% rename from docs/users/standalone/helloworldwithparams/js-run-params.json rename to docs/standalone/helloworldwithparams/js-run-params.json index 8e1c886c..9e665ba8 100644 --- a/docs/users/standalone/helloworldwithparams/js-run-params.json +++ b/docs/standalone/helloworldwithparams/js-run-params.json @@ -3,4 +3,4 @@ "name": "Visitor", "place": "Earth" } - } \ No newline at end of file +} From 4ed273bcf055caa7b0096fe69bccfe07858d5cc9 Mon Sep 17 00:00:00 2001 From: Jiaxin Fan Date: Mon, 6 Feb 2023 14:06:05 +0100 Subject: [PATCH 6/6] Replace filepath in curl --- docs/standalone/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/standalone/README.md b/docs/standalone/README.md index 8cc41a4b..500aeb7f 100644 --- a/docs/standalone/README.md +++ b/docs/standalone/README.md @@ -82,7 +82,7 @@ A container can only hold one function. This first example prepared a `js-init.j The json file contains a simple JavaScript (the target runtime language) function, which is the actual payload. ## Initialze the Runtime -Before issuing the action against the runtime, we first initialize the function with by invoking the ```/init``` endpoint. +Before issuing the action against the runtime, we first initialize the function with by invoking the ```/init``` endpoint with the `js-init.json` payload. ``` curl -H "Content-Type:application/json" -X POST --data '@/docs/users/standalone/helloworld/js-init.json' http://localhost:3008/init ```