Giter Club home page Giter Club logo

pfs-hellofun's Introduction

Hello Fun!

This project shows how to deploy a simple Java function to Pivotal Function Service (PFS).

Using PFS, you focus on your code, and you just deploy functions: the platform automatically optimizes resources usage, and takes care of packaging your functions to running containers.

This project contains the smallest possible Java function implementation, using the plain JDK Function interface. There are no external dependencies required. No even a Dockerfile!

public class Hello implements Function<String, String> {
    public String apply(String name) {
        final String n;
        if (name == null || name.isEmpty()) {
            n = "world";
        } else {
            n = name;
        }
        return "Hello " + n;
    }
}

As soon as you push this code to PFS, the platform compiles source code and generates a JAR file, which is then turned into an OCI container image using the Cloud Native Buildpack project.

How to use it?

Publish this function to PFS using this command:

$ pfs function create hello \
  --git-repo https://github.com/alexandreroman/pfs-hellofun.git \
  --handler fr.alexandreroman.demos.hellofun.Hello \
  --image $REGISTRY/$REGISTRY_USER/hello \
  --verbose

Invoke the function using this command:

$ pfs service invoke hello --text -- -w '\n' -d 'PFS'
curl 104.155.125.168/ -H 'Host: hello.hello.example.com' -H 'Content-Type: text/plain' -w '\n' -d PFS
Hello PFS

You can also use this function with a pipe:

$ whoami | pfs service invoke hello --text -- -w '\n' -d @-
curl 104.155.125.168/ -H 'Host: hello.hello.example.com' -H 'Content-Type: text/plain' -w '\n' -d PFS
Hello <username>

Contribute

Contributions are always welcome!

Feel free to open issues & send PR.

License

Copyright © 2018 Pivotal Software, Inc.

This project is licensed under the Apache Software License version 2.0.

pfs-hellofun's People

Contributors

alexandreroman avatar

Watchers

 avatar  avatar  avatar

Forkers

aspineon

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.