fn-logo
        

Fn Applications

Fn supports grouping functions into a set that defines an application (or API), making it easy to organize and deploy.

Create an app

This part is easy, just create an app.yaml file and put a name in it:

user input

mkdir myapp2

cd myapp2

echo 'name: myapp2' > app.yaml

This directory will be the root of your application.

Create a root function

The root function will be available at / on your application.

user input

fn init --runtime ruby

Now we have a Ruby function alongside our app.yaml.

Create a sub route

Now let’s create a sub route at /hello:

user input

fn init --runtime go hello

Now we have two functions in our app–one directly in the root folder and one in the hello folder. If you have the tree utility installed run:

user input

tree

This will show the structure we’ve created which looks like this:

.
├── Gemfile
├── app.yaml
├── func.rb
├── func.yaml
├── hello
│   ├── func.go
│   ├── func.yaml
│   └── test.json
└── test.json

Deploy the entire app

Now we can deploy the entire application with one command:

user input

fn deploy --all --local

Once the command is done we can examine the structure of the myapp2 application. First we can get a list of deployed applications. The l or list command, followed by a, app or apps displays the list of applications:

user input

fn list apps

You should see myapp2 in the list of deployed applications. We can then list application’s by using the l or list command, followed by r, route or routes:

user input

fn list routes myapp2

If you have previously set the FN_REGISTRY registry environment variable your Docker image names will be prefixed by it. Otherwise your output will look like:

/       myapp2-root:0.0.2 localhost:8080/r/myapp2
/hello  hello:0.0.2       localhost:8080/r/myapp2/hello

Once again l is a valid abbreviation for list followed by the object you wish to display, either apps or routes. We can see there are two routes / and /hello with two different Docker images assocated with them.

Let’s surf to our application. Open in a browser or use curl to call each of the functions.

  • Root function at: http://localhost:8080/r/myapp2/
  • And the hello function at: http://localhost:8080/r/myapp2/hello

Wrapping Up

Congratulations! In this tutorial you learned how to group functions into an application and deploy them with a single command.

Go: Back to Contents