You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by dg...@apache.org on 2019/10/14 14:57:24 UTC

[openwhisk-runtime-rust] branch master updated: update readme with usage instructions (#16)

This is an automated email from the ASF dual-hosted git repository.

dgrove pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openwhisk-runtime-rust.git


The following commit(s) were added to refs/heads/master by this push:
     new 4382a6d  update readme with usage instructions (#16)
4382a6d is described below

commit 4382a6ddbcaa58bdb3089642d2ec78454d8cc386
Author: Roberto Diaz <ro...@theagilemonkeys.com>
AuthorDate: Mon Oct 14 15:57:15 2019 +0100

    update readme with usage instructions (#16)
    
    Co-Authored-By: rodric rabbah <ro...@gmail.com>
---
 README.md | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 67 insertions(+), 3 deletions(-)

diff --git a/README.md b/README.md
index 56635c9..0ea2c2d 100644
--- a/README.md
+++ b/README.md
@@ -16,10 +16,74 @@
 # limitations under the License.
 #
 -->
-# openwhisk-runtime-rust
-
-Work in Progress... It will be awesome!
+# Apache OpenWhisk Runtime for Rust
 
 [![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0)
 [![Build Status](https://travis-ci.org/apache/openwhisk-runtime-rust.svg?branch=master)](https://travis-ci.org/apache/openwhisk-runtime-rust)
 
+### Give it a try today
+To use as a Docker action:
+
+```
+wsk action update myAction my_action.rs --docker openwhisk/actionloop-rust-v1.34
+```
+
+The file `my_action.rs` looks like:
+
+```
+extern crate serde_json;
+
+use serde_derive::{Deserialize, Serialize};
+use serde_json::{Error, Value};
+
+#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
+struct Input {
+    #[serde(default = "stranger")]
+    name: String,
+}
+
+#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
+struct Output {
+    body: String,
+}
+
+fn stranger() -> String {
+    "stranger".to_string()
+}
+
+pub fn main(args: Value) -> Result<Value, Error> {
+    let input: Input = serde_json::from_value(args)?;
+    let output = Output {
+        body: format!("Hello, {}", input.name),
+    };
+    serde_json::to_value(output)
+}
+```
+
+The action is mainly composed by a `main` function that accepts a JSON `serdes Value` as input and returns a `Result` including a JSON `serde Value`.
+
+### Managing dependencies
+
+If your action needs external dependencies, you need to provide a zip file including your source and your cargo file with all your dependencies. The folder structure is the following:
+```
+|- Cargo.toml
+|- src
+    |- lib.rs
+```
+Here is an example of a `Cargo.toml` file
+```
+[package]
+name = "actions"
+version = "0.1.0"
+authors = ["John Doe <jo...@doe.domain>"]
+edition = "2018"
+
+[dependencies]
+serde_json = "1.0"
+serde = "1.0"
+serde_derive = "1.0"
+```
+Once you have all your code zipped in a file with the showed folder structure you can generate your action with the following command:
+```
+wsk action create yourAction /full_path_to/yourCode.zip --docker openwhisk/actionloop-rust-v1.34
+```