/yapp

yaml app

Primary LanguageGo

yapp (pronounced /ʒæp/)

A framework for apps written entirely in YAML, powered by ytt.

Highly experimental! This is a ridiculous idea! Do not use!

# build & start the server...
make build
./yapp examples/hello-world/yapp.yml
# and then...
curl localhost:7000/hello -d '{"name": "reid"}'

how it works

You configure your app's routes in a yapp.yml file. You can use ytt to template this file!

Details about incoming HTTP requests will be passed to the template as data values under data.values.request.

These are the values that are currently provided to your template:

  • data.values.request.body: request body, parsed as YAML
  • data.values.request.headers: request headers (map[string]string[])
  • data.values.request.query: request query parameters (map[string]string[])

And these are the fields that you can set on your routes to control the HTTP responses:

  • status: HTTP status code for the response (int, defaults to 200 if not set)
  • headers: custom response headers to set (map[string]string[])
  • body: response body (can be anything YAML-marshallable)

examples

A simple yapp is just a YAML file like this:

routes:
  GET /hello:
    status: 200
    body:
      message: "hello!"

Run with yapp and try curl localhost:7000/hello:

$ curl localhost:7000/hello
message: hello!

But that's just plain YAML. It gets really fun when you start using ytt!

#@ load("@ytt:data", "data")
---
routes:
  POST /hello:
    status: 200
    body:
      message: "hello!"
      name: #@ data.values.request.body.name

Run with yapp and try curl localhost:7000/hello -d '{"name": "reid"}':

$ curl localhost:7000/hello -d '{"name": "reid"}'
message: hello!
name: reid

See the examples directory for more!