Giter Site home page Giter Site logo

faas-forward's Introduction

faas-forward

Chain OpenFaaS function

import github.com/s8sg/faas/forward

// Create a reusable chain
chain := forward.NewFuncChain().apply(“resize_image”, nil).apply(“color_image”, nil).apply(“add_saturation”, nil)
err = chain.Deploy()

// Invoke the chain
var io.ReadCloser result;
var err error;
result, err = chain.Invoke((io.Reader)image_file)



// Async invoke chain
chain = forward.NewFuncChain().apply(“resize_image”, nil).apply(“color_image”, nil).apply(“add_saturation”, nil).async_apply(“upload_to_storage”, map[string]string {.”url”, “http://file-storage:8080” })
err = chain.Deploy()
// Result is empty array if async reply
_, err = chain.Invoke((io.Reader)image_file)

Getting Started

Currently the automated chain creation is not implemented although you can do it manually by specifying a stack to chain functions

Manual

Pull the faas-forward template

faas-cli template pull https://github.com/s8sg/faas-forward

Currently only go template is available as forward-go

Create a new function

faas-cli new --lang forward-go myfunc

Implement the function

edit myfunc/handle.go

// Handle a serverless request
func Handle(req []byte) ([]byte, error) {
       return []byte(fmt.Sprintf("Hello, Go-Forward: %s. ", string(req))), nil
}

Define stack.yml

rename myfunc.yml to stack.yml
define stack.yml

provider:
 name: faas
 gateway: http://127.0.0.1:8080

# Stack equivalent of data.apply("myfunc1", nil).apply(“myfunc2”, nil).apply(“myfunc3”, nil)
functions:
  myfunc1:
   lang: forward-go
   handler: ./myfunc
   image: s8sg/myfunc:latest
   environment:
       input_type: "POST" // handle a POST request (also specify the begining of chain)
       async: false
       forward: myfunc2

  myfunc2:
   lang: forward-go
   handler: ./myfunc
   image: s8sg/myfunc:latest
   environment:
       # Default input type for forward function is multipart file (DATA)
       input_type: "DATA"
       # async allows to execute the nexy function in async manner
       async: false
       forward: myfunc3

  myfunc3:
   lang: forward-go
   handler: ./myfunc
   image: s8sg/myfunc:latest
   environment:
       # Default input type for forward function is multipart file (DATA)
       input_type: "DATA"
       # No forward defines the end of a chain

Execute

$ curl -X POST 127.0.0.1:8080/function/myfunc1 -d "Hello World"
Hello, Go-Forward: Hello World. Hello, Go-Forward: Hello World. Hello, Go-Forward: Hello World.

faas-forward's People

Contributors

s8sg avatar

Watchers

 avatar  avatar  avatar

Forkers

wiluen

faas-forward's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.