fdk 0.0.12 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3f057f3e89f9eb850ed4985a5f6126c8e8bfa48d
4
- data.tar.gz: 9cae6ab2bf5440ead52770fd6bd9169f3aa16827
3
+ metadata.gz: cd1f63ae8fc93bda3870e3ce780994e84b99e386
4
+ data.tar.gz: 045eebb796bd9eaae7a190dbd10c3bbb390c61a6
5
5
  SHA512:
6
- metadata.gz: 53027dd0dc51188135be54f0d6a669cf5dbb3e32a5b6bcecc504c7e96312ecb3237f9c5572b0e7675171fbbd9c0705ee1ac079851503b72d41c405308d652bfe
7
- data.tar.gz: 3e8f21b25c20dd5e8595c53a0cfa80fb1c7cef152a1f3f5914d628cd13b3b86a547a4a80494215ea11f52ba75ca0a3a8dc2ed5bc7fd259e01cace8203e6d8931
6
+ metadata.gz: 31677d766e3ae7d1dff6ccca614e5be549e5704dd2747406206496f3c2ec886fa48735d3fde66989b4840606b692f6b4cc2bde95da5c717f7ab5dedd2b70da57
7
+ data.tar.gz: 7a4d3a7d572e94f752ec2be0eacc44bcc49936643d7c9a63faf7ee57d4a832fa362a95c2daf095d5ad4718a06e469a853f1f2442bac21d6434157928983af2c3
data/README.md CHANGED
@@ -1,19 +1,17 @@
1
1
  # Ruby Function Developer Kit (FDK)
2
-
3
- This provides a Ruby framework for deleloping functions for us with [Fn](https://fnproject.github.io).
2
+ This provides a Ruby framework for developing functions for use with [Fn](https://fnproject.github.io).
4
3
 
5
4
  ## Function Handler
6
-
7
5
  To use this FDK, you simply need to require this gem.
8
6
 
9
7
  ```ruby
10
- require 'fdk`
8
+ require 'fdk'
11
9
  ```
12
10
 
13
11
  Then create a function with with the following syntax:
14
12
 
15
13
  ```ruby
16
- def myfunc(context, input)
14
+ def myfunction(context:, input:)
17
15
  # Do some work here
18
16
  return output
19
17
  end
@@ -22,16 +20,22 @@ end
22
20
  * context - provides runtime information for your function, such as configuration values, headers, etc.
23
21
  * input – This parameter is a string containing body of the request.
24
22
  * output - is where you can return data back to the caller. Whatever you return will be sent back to the caller. If `async`, this value is ignored.
25
- * Default output format should be in JSON, as Content-Type header will be `application/json` by default. You can be more flexible if you create and return
26
- an FDK::Response object instead of a string.
23
+ * Default output format should be in JSON, as Content-Type header will be `application/json` by default. You can be more flexible if you create and return
24
+ an FDK::Response object instead of a string.
27
25
 
28
26
  Then simply pass that function to the FDK:
29
27
 
30
28
  ```ruby
31
- FDK.handle(myfunction)
29
+ FDK.handle(:myfunction)
32
30
  ```
33
31
 
34
- ## Full Example
32
+ ## Examples
33
+
34
+ See the [examples](examples) folder of this repo for code examples.
35
+
36
+ ### Hello World Example
37
+
38
+ In the [hello-ruby](examples/hello-ruby) folder there is a traditional "Hello World" example. The code is found in [func.rb](examples/hello-ruby/func.rb):
35
39
 
36
40
  ```ruby
37
41
  require 'fdk'
@@ -45,44 +49,50 @@ end
45
49
  FDK.handle(function: :myfunction)
46
50
  ```
47
51
 
48
- ## Running the example that is in the root directory of this repo
52
+ ## Deploying functions
49
53
 
50
- ```sh
51
- $ echo '{"name":"coolio"}' | fn run
52
- {"message":"Hello coolio!"}
53
- ```
54
+ To use a function we need to deploy it to an fn server.
54
55
 
55
- You can also specify the format (the default is JSON)
56
+ In fn an _app_ consist of one or more functions and each function is
57
+ deployed as part of an app.
56
58
 
57
- ```sh
58
- $ echo '{"name":"coolio"}' | fn run --format json
59
- {"message":"Hello coolio!"}
60
- ```
59
+ We're going to deploy the hello world example as part of the app
60
+ `examples`.
61
61
 
62
- If you want to just pass plain text to the function, specify a format of __default__:
63
-
64
- ```sh
65
- $ echo 'coolio' | fn run --format default
66
- {"message":"Hello coolio!"}
67
- ```
62
+ With an fn server running (see
63
+ [Quickstart](https://github.com/fnproject/fn/blob/master/README.md) if you need instructions):
68
64
 
69
- Deploy:
65
+ `cd` to the [hello-ruby](examples/hello-ruby) folder and run:
70
66
 
71
67
  ```sh
72
- fn deploy --app myapp --local && echo '{"name":"coolio"}' | fn call myapp /fdk-ruby
68
+ fn deploy --app examples --local
73
69
  ```
74
70
 
75
- Change to hot:
71
+ The `--app examples` option tells fn to deploy the function as part of
72
+ the _app_ named _examples_.
73
+
74
+ The `--local` option tells fn not to push the function image to Docker
75
+ Hub.
76
76
 
77
- Update func.yaml: `format: json`
77
+ ## Invoking functions
78
+ Once we have deployed a function we can invoke it using `fn invoke`.
78
79
 
80
+ Running the [Hello World](examples/hello-ruby) example:
79
81
  ```sh
80
- fn deploy --app myapp --local && echo '{"name":"coolio"}' | fn call myapp /fdk-ruby
82
+ $ fn invoke examples hello
83
+ {"message":"Hello World!"}
84
+ ```
85
+ To get a more personal message, send a name in a JSON format and set the
86
+ `content-type 'application/json'`:
87
+ ```
88
+ echo '{"name":"Joe"}' | fn invoke examples hello --content-type
89
+ 'application/json'
90
+ {"message":"Hello Joe!"}
81
91
  ```
82
92
 
83
- ## Compare cold and hot
93
+ ## Compare cold and hot functions
84
94
 
85
- Run
95
+ Run [loop.rb](examples/loop.rb)
86
96
 
87
97
  ```sh
88
98
  ruby loop.rb
data/lib/fdk/runner.rb CHANGED
@@ -63,7 +63,7 @@ module FDK
63
63
  'type' => 'http',
64
64
  'request_url' => ENV['FN_REQUEST_URL']
65
65
  }
66
- output_stream.puts FDK.single_event(function: function, context: Context.new(event), input: input_stream.read).to_json
66
+ output_stream.puts FDK.single_event(function: function, context: Context.new(event), input: input_stream.read.chomp).to_json
67
67
  else
68
68
  raise "Format '#{format}' not supported in Ruby FDK."
69
69
  end
data/lib/fdk/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module FDK
2
- VERSION = "0.0.12"
2
+ VERSION = "0.0.13"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Travis Reeder
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-09-10 00:00:00.000000000 Z
12
+ date: 2018-09-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json