# TypeDialog Web Backend HTTP server with browser-based forms powered by [Axum](https://github.com/tokio-rs/axum). ## Overview The Web backend (`typedialog-web`) provides a full-featured HTTP server with browser-based forms. Built with Axum for high performance, supporting REST APIs, WebSockets, and modern web interfaces. ## Features - **HTTP Server**: Fast async server with Axum - **Browser Forms**: Responsive HTML forms with JavaScript - **REST API**: JSON endpoints for form submission - **Real-time Validation**: Client-side and server-side validation - **RepeatingGroups**: Inline expandable cards with live counter - **Mobile-Friendly**: Responsive design for all screen sizes - **HTTPS Support**: TLS/SSL for production - **Session Management**: Stateful forms with session persistence ## Quick Start ### Installation ```bash cargo build --release -p typedialog-web sudo cp target/release/typedialog-web /usr/local/bin/ # Or use just just build::web ``` ### Basic Usage ```bash # Start server (default: http://localhost:3000) typedialog-web --config examples/form.toml # Custom port typedialog-web --config form.toml --port 8080 # With HTTPS typedialog-web --config form.toml --tls-cert cert.pem --tls-key key.pem # From config file typedialog-web --config config/web/production.toml ``` ## Server Endpoints ### Form Endpoints | Method | Path | Description | | -------- | ------ | ------------- | | `GET` | `/` | Render form HTML | | `POST` | `/submit` | Submit form data | | `GET` | `/api/form` | Get form definition (JSON) | | `POST` | `/api/validate` | Validate field | | `GET` | `/health` | Health check | ### Static Assets | Path | Description | | ------ | ------------- | | `/static/css/form.css` | Form styles | | `/static/js/form.js` | Form logic | | `/static/js/repeating-group.js` | RepeatingGroup handler | ## Configuration ### Server Config ```toml [web] host = "0.0.0.0" port = 3000 tls_enabled = false [web.cors] allow_origin = "*" allow_methods = ["GET", "POST"] allow_headers = ["Content-Type"] [web.session] secret_key = "change-me-in-production" timeout_seconds = 3600 ``` ### TLS/HTTPS Config ```toml [web.tls] enabled = true cert_path = "/path/to/cert.pem" key_path = "/path/to/key.pem" ``` ### Form Config ```toml [form] title = "Registration Form" description = "User registration" submit_text = "Register" cancel_text = "Cancel" [[fields]] name = "email" field_type = "Text" label = "Email" validation = "email" required = true ``` ## API Usage ### Get Form Definition ```bash curl http://localhost:3000/api/form ``` Response: ```json { "form": { "title": "Registration", "fields": [...] } } ``` ### Submit Form ```bash curl -X POST http://localhost:3000/submit \ -H "Content-Type: application/json" \ -d '{"name":"John","email":"john@example.com"}' ``` Response: ```json { "status": "success", "data": { "name": "John", "email": "john@example.com" } } ``` ### Validate Field ```bash curl -X POST http://localhost:3000/api/validate \ -H "Content-Type: application/json" \ -d '{"field":"email","value":"invalid"}' ``` Response: ```json { "valid": false, "error": "Invalid email format" } ``` ## Frontend Features ### JavaScript API ```javascript // Form submission document.getElementById('form').addEventListener('submit', async (e) => { e.preventDefault(); const formData = new FormData(e.target); const data = Object.fromEntries(formData); const response = await fetch('/submit', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }); const result = await response.json(); console.log('Submitted:', result); }); // Real-time validation input.addEventListener('blur', async () => { const response = await fetch('/api/validate', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ field: input.name, value: input.value }) }); const result = await response.json(); if (!result.valid) { showError(result.error); } }); ``` ### RepeatingGroups The web backend renders RepeatingGroups as inline expandable cards: ```html