DEV Community

Thiago Mendes
Thiago Mendes

Posted on

Marreta Lang: a zero-ceremony DSL for REST APIs

A large part of backend work is still REST APIs that take a request, validate it, apply a rule, hit some infrastructure, and return a clear answer. You usually rebuild the same plumbing every time: a DB client, a serializer, a validation layer, a message consumer, a cache wrapper, an OpenAPI generator, all wired together before a single line of behavior.

Marreta Lang is a focused DSL for exactly that. You write the behavior, and the language provides the rest as building blocks. A route reads like what it does, with no imports, no app object, and no connection setup:

route GET "/accounts/:id"
    account = doc.accounts.find(params.id)
    require account else fail 404, "account not found"

    reply 200, account
Enter fullscreen mode Exit fullscreen mode

Validate and persist, declaratively

A schema describes the shape once. Binding it with take payload as validates the body before your route runs, so the body only ever sees data that already matches the contract. An invalid body returns a 422 automatically.

schema NewAccount
    owner: string

route POST "/accounts" take payload as NewAccount
    account = doc.accounts.save({ owner: payload.owner, balance: 0 })

    reply 201, account
Enter fullscreen mode Exit fullscreen mode

The request inputs are exposed directly as params, query, payload, headers, and auth. There is no req/request/ctx object to thread around.

Infrastructure as building blocks

Relational and document databases, cache, queues, topics, an HTTP client, and generated OpenAPI are built into the language and CLI, with zero project dependencies. Each is a namespace, and the provider behind it is just configuration, so the same code runs on different infrastructure by swapping the provider, not the code.

route GET "/products/:sku"
    product = db.products >> where(sku: params.sku) >> fetch_one
    require product else fail 404, "product not found"

    reply 200, product
Enter fullscreen mode Exit fullscreen mode

Relational schemas turn into tables through reviewable migrations:

marreta migrate generate   # writes the SQL from your schemas
marreta migrate apply      # the only step that changes the database
Enter fullscreen mode Exit fullscreen mode

Tests are a first-class concept

Scenario tests run in memory against mocked providers, so they need no database and return in milliseconds.

scenario "returns an account by id"
    given doc.accounts.find("acc_1") returns { owner: "Ana", balance: 500 }

    when GET "/accounts/acc_1"

    then status 200
    then response is { body: { owner: "Ana", balance: 500 } }
Enter fullscreen mode Exit fullscreen mode

A high-level language with a native footprint

Marreta is interpreted, but the runtime that interprets it is compiled to a native binary. There is no managed VM and no garbage collector: memory is released as values leave scope, and requests are served on an async, multi-threaded I/O model.

In practice that means a small, predictable resource footprint and a fast time to first request. It maps directly to cost: high container density (more services per node) and a cold start fast enough for serverless and scale-to-zero. The developer experience of a high-level language with the resource profile of a native one.

Ready for AI assistants

Most code today is written with an assistant in the editor, and a new language is exactly what models do not know. marreta init scaffolds an AGENTS.md primer, and the site serves llms.txt and llms-full.txt, both generated from the same docs and tested examples, so an assistant writes correct Marreta instead of guessing.

Try it

Marreta is new, launching at v0.2.0 under MIT, with rough edges I have not found yet. If it resonates, build something small and tell me where it falls short.

curl -fsSL https://raw.githubusercontent.com/tm-dev-lab/marreta-lang/main/install.sh | sh
marreta init demo
cd demo && marreta serve
Enter fullscreen mode Exit fullscreen mode

It is built in Brazil, and the name stays in Portuguese on purpose. Marreta means sledgehammer: break through the boilerplate to reach the code that actually describes the API.

Top comments (0)