Skip to content

High quality source of developer excuses

License

Notifications You must be signed in to change notification settings

mantil-io/example-excuses

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About

This is a simple Mantil project template that will demonstrate a few Mantil concepts. It has a single Lambda function that holds a list of programming excuses (strings). API has methods for:

The first concept to show is the use of environment variables. In this case we will use a project-wide environment variable. They can be also set at the individual stage level which is a way to configure the same Lambda function to work differently in different stages.
In our case we will use an environment variable to set preload_url which will be used during Lambda function cold start to load the initial list of excuses. If preload_url is not set application will start with an empty list of excuses.

The second concept is integration between UI and API. The project has a simple web page which will show random excuses, and on each click call API to get a new random excuse.

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

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

mantil new command has a flag --from for creating a new project from existing template.

We will use this set of commands to create a project from a template, create new stage and deploy a project to the stage.

mantil new my-excuses --from https://github.com/mantil-io/template-excuses
cd my-excuses
mantil deploy

After that we can load the project web page at URL:

open $(mantil env --url)

The web page should look like:

web page

Click on the excuse text to get a new random text.

Invoking Methods

Let's call some API methods:

mantil invoke excuses/count
mantil invoke excuses/random

We can use equivalent curl methods:

curl -X POST $(mantil env -u)/excuses/count
curl -X POST $(mantil env -u)/excuses/random

Explore the mantil logs command. It will show logs from the Lambda function execution. The first form will show all logs. Second only REPORT lines.

mantil logs excuses
mantil logs excuses --filter-pattern "REPORT"

Loading list of excuses

To clear current list execute:

mantil invoke excuses/clear

and check:

➜ mantil invoke excuses/random
Error: 500 Internal Server Error
X-Api-Error: no excuses

To load new list of excuses:

mantil invoke excuses/load --data '{"URL": "https://gist.githubusercontent.com/orf/db8eb0aaddeea92dfcab/raw/5e9a8958fce65b1fe8f9bbaadeb87c207e5da848/gistfile1.txt"}'

Some URLs for loading excuses lists:

https://gist.githubusercontent.com/ianic/f3335ba0b7ec63cbb821f8a7b735d86e/raw/066e44b04682295781164c538774db645dfe4cc6/excuses.txt

https://gist.githubusercontent.com/fortytw2/78f5f9ef915cb43a3be4/raw/286da386ad35785b2ed9f158e665c8129536e0ce/excuses.txt

https://gist.githubusercontent.com/orf/db8eb0aaddeea92dfcab/raw/5e9a8958fce65b1fe8f9bbaadeb87c207e5da848/gistfile1.txt

Web interface

index.html page from project /public folder is available at root URL. You can get the root URL by:

mantil env --url

or open in the browser with this terminal command:

open $(mantil env --url)

Random excuse in terminal

If you have jq (JSON processor), this is a useful one-liner to be ready when some manager comes into the room:

watch -t -n 5 'curl -s -X POST $(mantil env -u)/excuses/random | jq -r .Excuse'

Environment variable

Try to remove preload_url from config/environment.yml. After deploy function will always start with an empty list.

Test

Run tests with:

mantil test

Explore test/excuses_test.go file to get the feeling of how to use integration tests in Mantil.

Cleanup

Remove created stage with:

mantil stage destroy development

After that all resources created in the AWS account are removed. You can delete this test project folder.

cd ..
rm -rf my-excuses

About

High quality source of developer excuses

Resources

License

Stars

Watchers

Forks

Contributors 4

  •  
  •  
  •  
  •