Otter
Recipes
Otter
Upstream Recipe Tested
Web Portal Application Recipe
Full-stack web portal with HTTP routes, navigation menus, feedback forms, input validation, and persistent JSON storage.
Architecture & Runtime Preview
Otter >=1.0.1The recipe combines Otter's native HTTP routing and static file serving with `otter-official/file-helpers` for saving form submissions and `otter-official/text-utils` for string formatting.
- 1setup-routes: Establish HTTP endpoints for portal pages, submission forms, and JSON API (otter-official/text-utils)
- 2persist-submissions: Store validated feedback and form submissions in persistent JSON storage (otter-official/file-helpers)
Source Code (5 files)
{
"schemaVersion": 1,
"id": "otter-official/web-portal",
"version": "1.0.0",
"title": "Web Portal Application",
"summary": "Full-stack web portal with HTTP routes, navigation menus, feedback forms, input validation, and persistent JSON storage.",
"target": "server",
"requiresOtter": ">=1.0.1",
"capabilities": ["web", "files"],
"packs": [
{ "id": "otter-official/file-helpers", "version": "1.0.1" },
{ "id": "otter-official/text-utils", "version": "1.0.1" }
],
"configuration": [
{ "id": "portalName", "title": "Portal Title", "type": "text", "default": "Community Hub", "description": "Brand title for portal header and pages" },
{ "id": "portNumber", "title": "HTTP Port", "type": "number", "default": 8080, "description": "Local TCP port for web server" }
],
"steps": [
{
"id": "setup-routes",
"kind": "pack-call",
"description": "Establish HTTP endpoints for portal pages, submission forms, and JSON API",
"source": "otter-official/text-utils",
"inputs": [{ "name": "routePath", "type": "text" }],
"outputs": [{ "name": "response", "type": "text" }]
},
{
"id": "persist-submissions",
"kind": "pack-call",
"description": "Store validated feedback and form submissions in persistent JSON storage",
"source": "otter-official/file-helpers",
"inputs": [{ "name": "submissions", "type": "list" }],
"outputs": [{ "name": "saved", "type": "boolean" }]
}
],
"generatedFiles": [
{ "path": "src/server.ot", "template": "templates/server.ot.tmpl" },
{ "path": "public/index.html", "template": "templates/index.html.tmpl" }
],
"tests": [
"tests/test.ot"
],
"explanations": {
"beginner": "This application creates a web website with multiple pages, a navigation bar, and an online submission form. Messages sent through the form are checked for valid email addresses and saved to a file.",
"intermediate": "The recipe combines Otter39;s native HTTP routing and static file serving with `otter-official/file-helpers` for saving form submissions and `otter-official/text-utils` for string formatting.",
"advanced": "Implements RESTful HTTP routes on Kestrel/HttpListener. Static assets are served from the `public` directory while API routes validate payloads and persist records into JSON storage."
}
}
# ==============================================================================
# Generated by Otter Application Recipe: web-portal 1.0.0
# Target: Native HTTP Web Portal with Form Submissions and File Persistence
# ==============================================================================
use "${import:otter-official/file-helpers}"
use "${import:otter-official/text-utils}"
a Submission has
name
email
message
timestamp
.
to validateSubmission name email message
if name is ""
return false
.
if not email contains "@"
return false
.
if not email contains "."
return false
.
if message is ""
return false
.
return true
.
to createSubmission name email message
s is a Submission
name of s is name
email of s is email
message of s is message
timestamp of s is "2026-11-10T18:00:00Z"
return s
.
to saveSubmissions list filePath
convert list to json into rawJson
writeSafe filePath rawJson
return true
.
to loadSubmissions filePath
raw is readOrFallback filePath "[]"
loaded is a thing
convert raw from json into loaded
return loaded
.
to getNavigation
nav are empty
add "Home" to nav
add "Submissions API" to nav
add "Contact" to nav
return nav
.
# Web server declaration (Executed when started via `otter serve`)
site is a web server
port is ${config:portNumber}
host is "127.0.0.1"
static is "public"
.
when site receives GET at "/api/nav"
nav is getNavigation
respond with nav as json
.
when site receives GET at "/api/submissions"
subs is loadSubmissions "submissions_store.json"
respond with subs as json
.
when site receives POST at "/api/submit" into req
bodyData is a thing
convert body of req from json into bodyData
subName is name of bodyData
subEmail is email of bodyData
subMsg is message of bodyData
if validateSubmission subName subEmail subMsg
newSub is createSubmission subName subEmail subMsg
currentSubs is loadSubmissions "submissions_store.json"
add newSub to currentSubs
saveSubmissions currentSubs "submissions_store.json"
respond with newSub as json and status 201
otherwise
err has
error is "Validation failed: invalid name, email, or message"
.
respond with err as json and status 400
.
.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>${config:portalName}</title>
<style>
:root {
--bg: #0f172a;
--card-bg: #1e293b;
--text: #f8fafc;
--text-muted: #94a3b8;
--primary: #38bdf8;
--primary-hover: #0ea5e9;
--border: #334155;
}
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
background: var(--bg);
color: var(--text);
display: flex;
flex-direction: column;
min-height: 100vh;
}
header {
background: var(--card-bg);
border-bottom: 1px solid var(--border);
padding: 1rem 2rem;
display: flex;
justify-content: space-between;
align-items: center;
}
.brand {
font-size: 1.25rem;
font-weight: 700;
color: var(--primary);
}
nav a {
color: var(--text-muted);
text-decoration: none;
margin-left: 1.5rem;
transition: color 0.2s;
}
nav a:hover, nav a.active {
color: var(--text);
}
main {
flex: 1;
max-width: 800px;
margin: 2rem auto;
padding: 0 1rem;
width: 100%;
box-sizing: border-box;
}
.card {
background: var(--card-bg);
border: 1px solid var(--border);
border-radius: 8px;
padding: 1.5rem;
margin-bottom: 2rem;
}
h2 {
margin-top: 0;
color: var(--text);
}
label {
display: block;
margin-bottom: 0.5rem;
color: var(--text-muted);
font-size: 0.9rem;
}
input, textarea, button {
width: 100%;
padding: 0.75rem;
border-radius: 6px;
border: 1px solid var(--border);
background: #0b1120;
color: var(--text);
box-sizing: border-box;
margin-bottom: 1rem;
font-size: 1rem;
}
button {
background: var(--primary);
color: #0f172a;
font-weight: 600;
cursor: pointer;
border: none;
transition: background 0.2s;
}
button:hover {
background: var(--primary-hover);
}
footer {
text-align: center;
padding: 1.5rem;
color: var(--text-muted);
font-size: 0.85rem;
border-top: 1px solid var(--border);
}
</style>
</head>
<body>
<header>
<div class="brand">${config:portalName}</div>
<nav>
<a href="/" class="active">Home</a>
<a href="/api/submissions">Submissions API</a>
<a href="#contact">Contact</a>
</nav>
</header>
<main>
<div class="card">
<h2>Welcome to ${config:portalName}</h2>
<p>This web portal is generated by Otter 1.0.1 and served natively with persistent form submissions.</p>
</div>
<div class="card" id="contact">
<h2>Submit Feedback</h2>
<form action="/api/submit" method="POST">
<label for="name">Your Name</label>
<input type="text" id="name" name="name" required placeholder="Ada Lovelace">
<label for="email">Email Address</label>
<input type="email" id="email" name="email" required placeholder="ada@analytical.org">
<label for="message">Message</label>
<textarea id="message" name="message" rows="4" required placeholder="Enter your feedback here..."></textarea>
<button type="submit">Submit Feedback</button>
</form>
</div>
</main>
<footer>
Powered by Otter Native Web Runtime © 2026
</footer>
</body>
</html>
# ==============================================================================
# Test: Web Portal Application Logic
# ==============================================================================
use "../../../../packs/otter-official/file-helpers/src/main.ot"
use "../../../../packs/otter-official/text-utils/src/main.ot"
a Submission has
name
email
message
timestamp
.
to validateSubmission name email message
if name is ""
return false
.
if not email contains "@"
return false
.
if not email contains "."
return false
.
if message is ""
return false
.
return true
.
to createSubmission name email message
s is a Submission
name of s is name
email of s is email
message of s is message
timestamp of s is "2026-11-10T18:00:00Z"
return s
.
to saveSubmissions list filePath
convert list to json into rawJson
writeSafe filePath rawJson
return true
.
to loadSubmissions filePath
raw is readOrFallback filePath "[]"
loaded is a thing
convert raw from json into loaded
return loaded
.
to getNavigation
nav are empty
add "Home" to nav
add "Submissions API" to nav
add "Contact" to nav
return nav
.
# Test 1: Navigation routes
navItems is getNavigation
if length of navItems is not 3
say "FAIL: expected 3 navigation items"
.
# Test 2: Form validation
validPass is validateSubmission "Ada" "ada@analytical.org" "Great portal!"
if not validPass
say "FAIL: expected valid submission to pass"
.
invalidEmail is validateSubmission "Charles" "charles-no-at" "Missing at"
if invalidEmail
say "FAIL: expected invalid email to fail"
.
invalidMessage is validateSubmission "Alan" "alan@bletchley.uk" ""
if invalidMessage
say "FAIL: expected empty message to fail"
.
# Test 3: Data persistence
storeFile is "test_web_submissions.json"
testSubs are empty
s1 is createSubmission "Ada Lovelace" "ada@analytical.org" "First comment"
add s1 to testSubs
s2 is createSubmission "Charles Babbage" "charles@engines.org" "Second comment"
add s2 to testSubs
saveSubmissions testSubs storeFile
loadedSubs is loadSubmissions storeFile
if length of loadedSubs is not 2
say "FAIL: expected 2 loaded submissions"
.
writeSafe storeFile ""
say "Web-portal tests passed."
# ==============================================================================
# Demo: Web Portal Logic & Form Handler
# ==============================================================================
use "../../../../packs/otter-official/file-helpers/src/main.ot"
use "../../../../packs/otter-official/text-utils/src/main.ot"
a Submission has
name
email
message
timestamp
.
to validateSubmission name email message
if name is ""
return false
.
if not email contains "@"
return false
.
if not email contains "."
return false
.
if message is ""
return false
.
return true
.
to createSubmission name email message
s is a Submission
name of s is name
email of s is email
message of s is message
timestamp of s is "2026-11-10T18:00:00Z"
return s
.
to getNavigation
nav are empty
add "Home" to nav
add "Submissions API" to nav
add "Contact" to nav
return nav
.
say "=== Web Portal Demo ==="
nav is getNavigation
say "Portal Navigation:"
for each item in nav
say " - " plus item
.
say "Validating incoming contact submission..."
isValid is validateSubmission "Ada Lovelace" "ada@analytical.org" "Enjoying the portal design!"
if isValid
sub is createSubmission "Ada Lovelace" "ada@analytical.org" "Enjoying the portal design!"
say "Submission accepted from: " plus name of sub
.
say "Web-portal demo finished successfully."
Installation & Usage
otter recipe inspect otter-official/web-portal
otter recipe apply otter-official/web-portal --project ./my-app
This application creates a web website with multiple pages, a navigation bar, and an online submission form. Messages sent through the form are checked for valid email addresses and saved to a file.