Capy-Bearer Documentation

1. Getting started

Capy programs run as Bearer units. A source file uses the .capy suffix. Bearer compiles the file when a request first uses it.

Your first page

Create site/hello.capy:

function RENDER(request : dval) {
    print("Hello, Capy!\n")
}

Output

Hello, Capy!

RENDER is the entry point for a web request. print adds text to the response. The \n escape adds a newline.

Request the page through Bearer's default local HTTP socket:

curl --unix-socket /run/bearer/http.sock http://localhost/hello.capy

The command prints the response body. Bearer logs compiler and runtime errors.

Add a value

A local declaration uses :=. Capy infers the type from the value:

function RENDER(request : dval) {
    var name := "Ada"
    print("Hello, ", name, "!\n")
}

print accepts several arguments and writes them in order.

Write HTML

An HTML literal produces a string with escaped dynamic text:

function RENDER(request : dval) {
    var name := "Ada"
    print(<><h1>Hello, <?= name ?>!</h1></>)
}

print writes the string to the response. An HTML literal alone does not produce output. The Strings and HTML chapter explains escaping.

If it does not run

Confirm that bearer.service is active. The source file must be below the configured site directory. The CLI helper must use the configured local socket.

Make the first change small

Change one value and request the page again. For example, change Ada to your name. This proves that Bearer sees the file you edited.

Then add one standard-library call, such as request.out.headers["Content-Type"] = "text/plain; charset=utf-8". Small changes make compiler errors easier to isolate.

Continue with basic source syntax before you add request data or application APIs.