Quick Start
Build and run your first Terranova application in under five minutes.
Step 1: Create a specification file
Create a new file called app.kdl with the following content:
application "CatManager" version="0.1" {
entity "Cat" {
schema {
pk "id" type="int"
field "name" type="string"
field "age" type="int"
}
queries {
get "cat_by_id" sql="SELECT id, name, age FROM cat WHERE id = :id" {
param "id" type="int"
}
}
views {
template "/" query="cat_by_id" html="
<!DOCTYPE html>
<html>
<head><title>Cat Profile</title></head>
<body>
{{#data}}
<h1>{{name}}</h1>
<p>Age: {{age}} years</p>
{{/data}}
</body>
</html>
"
}
}
profile "dev" default=true {
listen address="127.0.0.1" port=8080
}
}
What's happening here?
| Block | Purpose |
|---|---|
application |
Root container; sets name and version. |
entity "Cat" |
Defines a data model for cats. |
schema |
Describes the database table: primary key id, fields name and age. |
queries |
Contains a custom get query to fetch a cat by ID (used by the HTML view). |
views |
Exposes the query as an HTML page at / (home). The id (ie: /id?=1) in the url query is automatically passed to the respective query parameter. |
profile |
Defines a development server listening on 127.0.0.1:8080. this profile will be automatically selected if no profile is profided at the server's starup |
Auto-generated CRUD
Even though we only defined a custom
getquery for the HTML view, Terranova automatically creates full CRUD endpoints for every entity:
POST /cat/– create a new catGET /cat/– retrieve all cats as JSONPUT /cat/– update a catDELETE /cat/?id=<id>– delete a catYou don't need to write any SQL for these basic operations.
Step 2: Run the application
Open a terminal in the same directory as app.kdl and run:
Terranova will:
- Parse the
.kdlfile. - Create a SQLite database (if missing) and generate the
cattable. - Start an HTTP server on
http://127.0.0.1:8080.
Keep the server running.
Note: You can kill the server by hitting
ctr+corcmd+c(in macos)
Step 3: Create a cat via the auto‑generated API
Open a second terminal and use curl or any other tool to send a POST request:
You should see a response like:
This means Garfield was created.
Note: The auto‑generated
POST /catendpoint expects JSON with the fields defined in the schema (nameandage).
Step 4: View the cat’s HTML profile
Open your browser and visit: http://127.0.0.1:8080/?id=1
You should see:
Congratulations — you've built a working REST API with auto‑generated CRUD and a custom HTML view using Terranova!
What you learned
- Define an
entitywith aschema– Terranova creates the database table and REST endpoints. - Auto‑generated CRUD lets you create, read, update, and delete records without writing SQL.
- Custom
queriesandviewsallow you to build dynamic HTML pages. profilesconfigure the server for different environments.