Your first API
Build a small JSON API with only the atlantus CLI.
1. Scaffold
atlantus new hello-api
cd hello-api
2. Add a route module
Create app/routes/hello.atl:
module hello
get "/hello" {
def hello(req) {
return json({ message: "Hello, Atlantus!" })
}
}
get "/hello/{name}" {
def hello_name(req) {
let name = req.param("name")
return json({ message: "Hello, " + name + "!" })
}
}
3. Wire the module
Open the scaffold entry (usually app/main.atl or app/routes/mod.atl) and
import your module the same way other route modules are imported in the
generated tree. If the scaffold already globs routes, a new file under
app/routes/ may be enough — run atlantus check and fix any “unknown module”
diagnostics.
Typical pattern:
import routes.hello
(Exact import syntax follows your generated app/ layout — prefer matching
existing imports in the scaffold.)
4. Run
atlantus check --path .
atlantus dev --path . --port 3000
curl -sS http://127.0.0.1:3000/hello
curl -sS http://127.0.0.1:3000/hello/Ada
5. HTML page (optional)
get "/hi/{name}" {
def hi(req) {
let name = req.param("name")
return view("hello/show", { "name": name })
}
}
app/views/hello/show.html:
@extends("layouts/app")
@section("content")
<h1>Hello, {{ name }}!</h1>
@endsection
See HTML views.
Response helpers
| API | Meaning |
|---|---|
json(body) | HTTP 200 + JSON |
json(body, 201) | Created |
status(204) | No body |
html(body) | HTML string response |
view(path, data) | File template → HTML response |
More: Built-in API.
Checklist
-
atlantus checkgreen - Route listed when
atlantus devstarts -
curlreturns the expected JSON
Next: Project layout.