Inofficial OpenFaaS template for the crystal programming language 🎉
To find out more about the OpenFaaS templates see the faas templates and faas-cli.
Go to your openFaaS project and execute:
faas-cli template pull https://github.com/TPei/crystal_faas_template
Alternatively, the template is also available via the OpenFaaS template store
faas-cli template store pull crystal
This will pull the template into your directory and allow you to use
faas-cli new --lang crystal my_function
to create a new crystal function
See crystal_faas_whalesay_demo for an implementation example.
It installs the latest version available on alpine.
As with all OpenFaaS templates, this template creates a my_function/handler.cr
file, as well as a my_function.yml
. In addition to this, a my_function/shard.yml
is created for your dependencies.
When building your function with faas-cli build -f my_function.yml
your dependencies will be resolved according to your shard file.
Hander#run
gets passed a req
String, if you want to handle json, simply do JSON.parse(req)
and do your thing :)
Your function always needs to return JSON, like so: return JSON::Any.new("Just a String, but JSON!")
require "json"
class Handler
def run(req : String)
whale = <<-WHALE
#{"-" * req.size}
< #{req} >
#{"-" * req.size}
\\
\\
\\
\\ ## .
\\## ## ## ==
## ## ## ## ## ===
/"""""""""""""""""\\___/ ====
~~~ ~~{~ ~~~ ~~~~~ ~~~~~ ~~~/~~====-~ ~~~~
\\______ O __/
\\ \\ __/
\\____\\_______/
WHALE
return JSON::Any.new(whale)
end
end
See contributing guide.
This project is licensed under the MIT License.