Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/TPei/crystal_openfaas
OpenFaaS template for the crystal programming language
https://github.com/TPei/crystal_openfaas
Last synced: about 1 month ago
JSON representation
OpenFaaS template for the crystal programming language
- Host: GitHub
- URL: https://github.com/TPei/crystal_openfaas
- Owner: TPei
- License: mit
- Created: 2018-10-02T12:31:59.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-04-29T04:01:35.000Z (8 months ago)
- Last Synced: 2024-05-21T01:05:01.089Z (7 months ago)
- Language: Shell
- Size: 51.8 KB
- Stars: 22
- Watchers: 2
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-crystal - crystal_openfaas - Template to enable crystal as first class citizens in OpenFaaS (Serverless Computing)
README
# Crystal OpenFaaS Template [![Runs on Crystal](https://repology.org/badge/version-for-repo/alpine_edge/crystal-lang.svg)](https://repology.org/project/crystal-lang/versions)
Inofficial OpenFaaS template for the crystal programming language 🎉
To find out more about the OpenFaaS templates see the [faas templates](https://github.com/openfaas/templates) and [faas-cli](https://github.com/openfaas/faas-cli).
## Usage
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 functionSee [crystal_faas_whalesay_demo](https://github.com/TPei/crystal_faas_whalesay_demo) for an implementation example.
## Which version of crystal is this running?
It installs the latest version [available on alpine](https://pkgs.alpinelinux.org/packages?name=crystal).
## Development
### General
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.
### Code
`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!")`
```crystal
require "json"class Handler
def run(req : String)
whale = <<-WHALE
#{"-" * req.size}
< #{req} >
#{"-" * req.size}
\\
\\
\\
\\ ## .
\\## ## ## ==
## ## ## ## ## ===
/"""""""""""""""""\\___/ ====
~~~ ~~{~ ~~~ ~~~~~ ~~~~~ ~~~/~~====-~ ~~~~
\\______ O __/
\\ \\ __/
\\____\\_______/
WHALE
return JSON::Any.new(whale)
end
end
```## Templates Developers / Contributors
See [contributing
guide](https://github.com/openfaas/templates/blob/master/CONTRIBUTING.md).## License
This project is licensed under the MIT License.