Skip to content
spaceport / docs
The Spaceport handbook

Rapid iteration: a Todo application

Build dynamic web applications using Source Modules to organize your backend logic and Routing to handle HTTP requests. Spaceport's Alert-driven Event System connects these pieces together, letting you define endpoints, business logic, and data flows in one cohesive codebase. Changes to your Groovy modules take effect immediately—no rebuilds required—so you can iterate as fast as you can type.

/// modules/Todo.groovy

import spaceport.computer.alerts.Alert
import spaceport.computer.alerts.results.*
import spaceport.computer.memory.virtual.*
import spaceport.launchpad.Launchpad

class Todo {

    // Use Alerts to hook into routing events, even with dynamic parameters
    @Alert('~on /todo/(.*) hit')
    static _index(HttpResult r) {
        // Middleware encouraged
        r.context.data.'todo-list' = Cargo.fromStore('todo-lists').get(r.matches[0])
        // Render UI with Launchpad's HTML-first templates
        new Launchpad().assemble(['ui.ghtml']).launch(r)
    }

    // Endpoints don't have to serve fancy templates
    @Alert('on /api/todo/get-all hit')
    static _getAll(HttpResult r) {
        // Provide a quick JSON API endpoint
        r.writeToClient(Cargo.fromStore('todo-lists').toPrettyJSON())
    }
}

Build interactive UIs with Launchpad's HTML-first templates that embed Groovy directly in your markup. Cargo provides a universal data container for common frontend/backend patterns, while Launchpad's .ghtml templates offer reactive data binding—when server state changes, your UI updates automatically. Server Actions connect DOM events to server-side logic, and Class Enhancements like .clean(), .quote(), and .if() handle common template tasks like sanitizing input, escaping strings, and conditional rendering. Build real-time interactivity without the boilerplate, while keeping full control to add custom JavaScript when you need it.

/// launchpad/parts/ui.ghtml

<%@ page import="spaceport.computer.memory.virtual.Cargo" %>
<script src="https://cdn.jsdelivr.net/gh/spaceport-dev/hud-core.js@latest/hud-core.js" defer></script>

<body>
/// Use the context provided by the router
<% def list = data.'todo-list' as Cargo %>

/// Reactively render the list
${{ list.combine { def item -> """
<div class="item ${ 'done'.if { item.done }}">

    /// Server actions provide seamless interactivity
    <span on-click=${ _{ item.toggle('done') }}>
    ${ item.done ? '✓' : '○' }
    </span>

    /// Conditional attributes, client transmissions, and input cleaning
    /// provide a safe and dynamic user experience
    <input ${ 'disabled'.if { item.done }}
    on-blur=${ _{ t -> item.text = t.value.clean() }}
    value=${ item.getString('text').quote() }>
</div>
""" }
}}

<button on-click="${ _{ list.setNext() }}">Add New</button>
</body>

This combined example shows how Spaceport's systems work together: Cargo simplifies state, Server Actions handle events like on-click and on-blur, and Class Enhancements provide utilities like .clean(), .quote(), .if(), and .combine() for cleaner templates. The Alert system wires routes to handlers, while Launchpad's reactive block ${{ }} syntax makes your UI reactive to server changes. Beyond what's shown here, Spaceport also provides Documents for database persistence, Server Elements for reusable components, Docking Sessions & Client Management for authentication, and more. Ready to dive in? Start with Getting Started or jump straight to building your first app with the Tic-Tac-Toe Tutorial.

Try the live Todo demo.

Make the docs better.Edit this page on GitHub