Code Monkey home page Code Monkey logo

fx's Introduction

fx

Poor man's function as a service.
build codecov Go Report Card Go Doc Release

Introduction

fx is a tool to help you do Function as a Service on your own server. fx can make your stateless function a service in seconds. The most exciting thing is that you can write your functions with most programming languages, you can refer to the doc to make fx support the language not listed bellow.

Language Status Contributor
Go Supported fx
Node Supported fx
Python Supported fx
Ruby Supported fx
Java Supported fx
PHP Supported @chlins
Julia Supported @mbesancon
D Supported @andre2007
R Working on need your help

Welcome to tweet me or Buy me a coffee.

Thank you to all the people who already contributed to fx!

metrue pplam muka xwjdsh mbesancon avelino DaidoujiChen chlins andre2007 andre2007

Installation

  • MacOS
brew tap metrue/homebrew-fx
brew install fx
  • Linux/Unix

To install fx, you can use the install script using cURL:

curl -o- https://raw.githubusercontent.com/metrue/fx/master/bin/install.sh | bash

or Wget:

wget -qO- https://raw.githubusercontent.com/metrue/fx/master/bin/install.sh | bash

fx will be installed into /usr/local/bin, if fx not found after installation, you may need to checkout if /usr/local/bin/fx exists. sometimes you may need source ~/.zshrc or source ~/.bashrc to make fx available on $PAHT.

  • Window

You can go the release page to download fx manually;

Usage

Make sure Docker installed and running on your server first.

  • start server
fx serve

now you can make a function to service in a second.

fx up ./examples/functions/func.js

the function defined in examples/functions/func.js is quite simple, it calculates the sum of two numbers then returns:

module.exports = (input) => {
    return parseInt(input.a, 10) + parseInt(input.b, 10)
}

then you can test your service:

curl -X POST <service url> -H "Content-Type: application/json" -d '{"a": 1, "b": 1}'

of course you can do more.

Usage:
$ fx serve                                      start f(x) server
$ fx up   func1.js func2.py func3.go ...        deploy a function or a group of functions
$ fx down [service ID] ...                      destroy a function or a group of functions
$ fx list                                       list deployed services
$ fx --version                                  show current version of f(x)

How to write your function

functions example with Node, Ruby, Python, PHP, Go, Java, Julia.

  • Node/JavaScript
module.exports = (input) => {
    return parseInt(input.a, 10) + parseInt(input.b, 10)
}
  • Ruby
def fx(input)
    return input['a'] + input['b']
end
  • Python
def fx(input):
    return input['a'] + input['b']
  • PHP
<?php
    function Fx($input) {
        return $input["a"]+$input["b"];
    }
  • Go
package main

type Input struct {
	A int32
	B int32
}

type Output struct {
	Sum int32
}

func Fx(input *Input) (output *Output) {
	output = &Output{
		Sum: input.A + input.B,
	}
	return
}
  • Java
package fx;

import org.json.JSONObject;

public class Fx {
    public int handle(JSONObject input) {
        String a = input.get("a").toString();
        String b = input.get("b").toString();
        return Integer.parseInt(a) + Integer.parseInt(b);
    }
}
  • Julia
struct Input
    a::Number
    b::Number
end

fx = function(input::Input)
    return input.a + input.b
end

Development Status

fx use Project to manage the development.

Contributing

Requirements
  • Docker: make sure Docker installed and running on your server.
  • dep: fx project uses dep to do the golang dependency management.
  • protoc / grpc: Used for RPC and types definition (See a setup script example)
Build and Run
$ git clone https://github.com/metrue/fx.git
$ cd fx
$ make install-deps && make build
$ ./build/fx serve                      # start your fx server
$ ./build/fx up func.js                 # deploy a function

LICENSE

MIT

fx's People

Contributors

andre2007 avatar avelino avatar chlins avatar daidoujichen avatar johnlunney avatar matbesancon avatar metrue avatar muka avatar pplam avatar steventhanna avatar xwjdsh avatar

Watchers

 avatar  avatar  avatar

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.