Home

Awesome

About

Mantil is a modern open-source framework for writing serverless apps in Go. It allows you to quickly create and deploy applications that use AWS Lambda over a command line interface.

This example shows how to create a simple sign-up workflow using Mantil. It consists of two steps:

Prerequisites

This example is created with Mantil. To download Mantil CLI on Mac or Linux use Homebrew

brew tap mantil-io/mantil
brew install mantil

or check direct download links.

To deploy this application you will need an AWS account.

Installation

To locally create a new Mantil project, run:

mantil new app --from signup
cd app

It will download this code to the app/api/signup/ directory on your machine, where you can explore and adjust it if necessary.

Configuration

In order for mailing to work properly, you will need to configure some environment variables:

Finally, here is an example configuration:

project:
  stages:
    - name: development
      functions:
      - name: signup
        env:
          APP_NAME: Mantil
          SOURCE_MAIL: hello@mantil.com

Deploying the application

Note: If this is the first time you are using Mantil you will need to install Mantil Node on your AWS account. For detailed instructions please follow the setup guide

mantil aws install

Then you can proceed with application deployment.

mantil deploy

This command will create a new stage for your project with the default name development and deploy it to your node.

You will now have access to three methods:

An example sign-up flow might look like this:

First, we invoke the register method:

mantil invoke signup/register -d '{"email":"daniel@mantil.com","name":"Daniel"}'

After receiving the mail with the activation code, we use it to invoke the activate method:

mantil invoke signup/activate -d '{"activationCode":"b74012e1-0137-445a-bcb5-47842a9efa3e"}'

This returns a token that we can verify using the verify method:

mantil invoke signup/verify -d '{"token":"eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCJ9.eyJhY3RpdmF0aW9uQ29kZSI6ImI3NDAxMmUxLTAxMzctNDQ1YS1iY2I1LTQ3ODQyYTllZmEzZSIsImFjdGl2YXRpb25JRCI6ImM3ZDMwOTIwLTE5NmQtNGViZi04ZTMwLTFjMWJjYjViOGUwMSIsImNyZWF0ZWRBdCI6MTY0MTkwNjM4NTQwMSwiaWF0IjoxNjQxOTA2Mzg1LCJleHAiOjE2NzM0NDIzODV9.kgtrAJ4Wm3DkjVdbH_cTm576LsD9GZG8P4zmVbDrCVJSUueIsx_RIJ0oKPSag569D4fzbpz-JF_dSSnlPvZ7BA"}'

which returns the decoded token:

200 OK
{
   "activationCode": "b74012e1-0137-445a-bcb5-47842a9efa3e",
   "activationID": "c7d30920-196d-4ebf-8e30-1c1bcb5b8e01",
   "createdAt": 1641906385401
}

Cleanup

To remove the created stage from your AWS account destroy it with:

mantil stage destroy development

Final thoughts

This example uses Mantil's persistent key/value storage that you can learn more about in the todo example.

If you have any questions or comments on this template or would just like to share your view on Mantil contact us at support@mantil.com.