GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - fnproject/fdk-ruby: Ruby Function Developer Kit

BranchesTags
Open more actions menu

Latest commit

 

History

238 Commits
238 Commits

Folders and files

NameName
Last commit message
Last commit date
examples
examples
 
 
lib
lib
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
.rubocop.yml
.rubocop.yml
 
 
LICENSE
LICENSE
 
 
NOTICE.txt
NOTICE.txt
 
 
README.md
README.md
 
 
Rakefile
Rakefile
 
 
THIRD_PARTY_LICENSES.txt
THIRD_PARTY_LICENSES.txt
 
 
fdk.gemspec
fdk.gemspec
 
 

Repository files navigation

Function Development Kit for Ruby

The Function Development Kit for Ruby (FDK for Ruby) provides a Ruby framework for developing functions for use with Fn.

CircleCI

Function Handler

To use this FDK, you simply need to require this gem.

require 'fdk'

Then create a function with with the following syntax:

def myfunction(context:, input:)
    # Do some work here
    return output
end
  • context - provides runtime information for your function, such as configuration values, headers, etc.
  • input – This parameter is a string containing body of the request.
  • 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.
  • 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 an FDK::Response object instead of a string.

Then simply pass that function to the FDK:

FDK.handle(target: :myfunction)

Examples

See the examples folder of this repo for code examples.

Hello World Example

In the hello-ruby folder there is a traditional "Hello World" example. The code is found in func.rb:

require 'fdk'

def myfunction(context:, input:)
  input_value = input.respond_to?(:fetch) ? input.fetch('name') : input
  name = input_value.to_s.strip.empty? ? 'World' : input_value
  { message: "Hello #{name}!" }
end

FDK.handle(target: :myfunction)

Deploying functions

To use a function we need to deploy it to an fn server.

In fn an app consist of one or more functions and each function is deployed as part of an app.

We're going to deploy the hello world example as part of the app examples.

With an fn server running (see Quickstart if you need instructions):

cd to the hello-ruby folder and run:

fn deploy --app examples --local

The --app examples option tells fn to deploy the function as part of the app named examples.

The --local option tells fn not to push the function image to Docker Hub.

Invoking functions

Once we have deployed a function we can invoke it using fn invoke.

Running the Hello World example:

$ fn invoke examples hello
{"message":"Hello World!"}

To get a more personal message, send a name in a JSON format and set the content-type 'application/json':

echo '{"name":"Joe"}' | fn invoke examples hello --content-type 'application/json'
{"message":"Hello Joe!"}

About

Ruby Function Developer Kit

fnproject.github.io

Resources

Readme
Apache-2.0 license
Activity
Custom properties

Stars

9 stars

Watchers

30 watching

Forks

1 fork
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.