Giter Club home page Giter Club logo

openfaas-clojure-template's Introduction

OpenFaaS Clojure Template

For a more in-depth walkthrough, please see my introductory post.

Installation

To install this template, run the following command:

faas-cli template pull https://github.com/tessellator/openfaas-clojure-template

If you ever need to update the template, simply run the the command above with the --overwrite flag.

This command will create (if necessary) a new folder template and add this template to it.

You can read more about how templates work in the faas-cli documentation.

Usage

Create a new function with the following command:

faas-cli new my-function --lang=clojure

A new project using deps.edn will be created. It will contain a function.core namespace that is required for the template to work properly. The requirement for this namespace is to have a ring handler defined as app. The app will be run in a jetty server in production.

You may add and use ring middleware and other libraries per usual.

ARM64 Support

The OpenJDK image used to build the function does not currently support the ARM64 architecture. There is an alternative image that may be used to get this support.

If you need to enable ARM64 support you should edit the Dockerfile and follow the instructions at the top of the file. This will be streamlined in a future release when the official OpenJDK images support ARM64.

Using compojure

If you would like your function to support subroutes of your main function route, you can use compojure to specify the subroutes. It is important to note that you only need to specify the subroute in your route definitions.

For example, in order to handle a call to /function/my-function/subroute/1234, the my-function function might contain the following definition:

(GET "/subroute/:id" [id]
  ...)

Adding items to the uberjar manifest

It can occasionally be useful to add properties to the uberjar, such as specifying the Implementation-Version. This template will apply the properties defined in a manifest.mf file in the top-level function folder (alongside the deps.edn file).

Running a server during local development

The template provides development tools for running a Jetty server locally during development. The additional features are associated with the dev alias, so to access them you must use the following command to launch a REPL.

clj -A:dev

The REPL will now have access to the function.server namespace located in the dev folder. You can start the server with the following commands:

(require '[function.server :as server])
(server/start!)

You can provide Jetty options to the start! function. For convenience, the options are stored between calls and are not necessary for subsequent calls to start!.

You can stop the server by calling the stop! function.

License

Copyright © 2019-2021 Thomas C. Taylor and contributors.

Distributed under the MIT License, the same as OpenFaaS.

openfaas-clojure-template's People

Contributors

tessellator avatar ccfontes avatar

Watchers

James Cloos 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.