An open API service indexing awesome lists of open source software.

https://github.com/stackbuilders/haskell-faas-template

Haskell Faas Template
https://github.com/stackbuilders/haskell-faas-template

Last synced: 19 days ago
JSON representation

Haskell Faas Template

Awesome Lists containing this project

README

          

# Developing in Haskell

Here you will find a Haskell template to start developing functions working with the HTTP protocol.

## Making a Function

In order to interact with HTTP protocol, we need to use the `haskell-http` function template:

```
faas-cli template pull git@github.com:stackbuilders/haskell-faas-template.git
```

This will pull all the templates available in the Stackbuilders repository.

Then, we will create a new haskell function using:

```
faas-cli new --lang haskell-http
```

Replace the `` with a descriptive name for your function.

Now, we will get a description of our project in the `.yml` file. The `` directory contains the necessary resources to implement our "lambda" function. It should look like this:

![](img/directory-structure.png)

Inside the `` directory we will find:

- `cabal.project`: Here you can import libraries that are not present in [Hackage](https://hackage.haskell.org/) (i.e. custom libraries)
- `haskell-template-function.cabal`: Here you will import the libraries needed in order to build the function. You can import libraries inside the `build-depends` section like this:

![](img/import-libraries.png)

- `src`: In this directory you will find the `Handler.hs`. This is the "main" module for your FaaS function. This is the module responsible for taking the input and outputting the response.
- `test`: Directory with the `HandlerSpec.hs` file. Here you can use the `Hspec` library to write tests for your function.

For this template we use Scotty as our web framework,we choose it because Scotty is a cheap and cheerful way to write RESTful, declarative web applications. When you want to create a page it is as simple as defining the verb, url pattern, and Text content. Besides, it is template-language agnostic. Anything that returns a Text value will do. And, it Uses very fast Warp web server by default.

### Note:

We have used an oficial image from Docker to create a personalized one to harbor the needed precompiled dependencies. It is possible to visualize it at the next repository: [https://github.com/stackbuilders/haskell-faas-template]