API

The API will use terraform output to build HTTP responses

Building a freaking API

This endpoint is running at https://api.terrable.work/v1/hello. Give it a try!

module "req" { source = "../http-request" http = var.http headers = var.headers payload = var.payload } locals { # Accept either the JSON "name" field or the name parameter name = module.req.json != null ? lookup(module.req.json, "name", var.default) : lookup(module.req.params, "name", var.default) } module "res" { source = "../http-response" content = { message = "Hello, ${local.name}!" } } output "response" { value = module.res.response }

Run the Hello API

git clone https://gitlab.com/jonathanbaugh/terrable.git docker-compose up

Make a Request

$ curl http://localhost:8000/?name=Jonathan {"message":"Hello, Jonathan!"}

The Components

The HTTP Request Module

The http-request module makes it easier to deal with incoming HTTP requests.

variable "http" {} variable "headers" {} variable "pathload" {} module "req" { source = "../http-request" http = var.http headers = var.headers payload = var.payload } output "response" { value = module.res.response }

The HTTP Response Module

The http-response module makes it easier to build your HTTP response.

module "res" { source = "path/to/http-response" content = { message = "Hello World!" } } output "response" { value = module.res.response }