The Client-Server Protocol
UIML uses a simple JSON-based protocol:- Metadata Request: Client requests metadata for a form
- Metadata Response: Server responds with form metadata (structure, fields, validation rules)
- Form Submission: Client submits form data
- Form Response: Server responds with results and output metadata
TypeScript Metadata Classes
The framework provides TypeScript classes to work with metadata in a type-safe manner. These are available in theuimf-core package.
FormMetadata
Represents the complete metadata for a form (source:uimf-core/src/FormMetadata.ts:8):InputFieldMetadata
Defines metadata for a single input field (source:uimf-core/src/InputFieldMetadata.ts:6):OutputFieldMetadata
Defines metadata for a single output field (source:uimf-core/src/OutputFieldMetadata.ts:6):FormResponse
Represents the server’s response after form submission (source:uimf-core/src/FormResponse.ts:6):Example Metadata JSON
Here’s what the metadata looks like when serialized (from README.md):Implementing a Client
To create a UIMF client, you need to:- Fetch metadata from the server
- Render input fields based on field type
- Handle form submission
- Render output fields based on field type
Step 1: Fetching Metadata
Step 2: Rendering Input Fields
Create a component registry that maps component types to React/Vue/Svelte components:Step 3: Handling Form Submission
Step 4: Rendering Output Fields
Reference Implementation: uimf-svelte
The uimf-svelte project is a full-featured UIMF client built with Svelte. It demonstrates:- Complete component library (inputs and outputs)
- Event handler system
- Form validation
- Dynamic form rendering
- Type-safe metadata handling
Key Features
Component Architecture:Custom Properties Pattern
Components usecustomProperties to pass configuration from server to client:
Event Handlers
Event handlers allow server-defined client-side behavior:Best Practices
- Use TypeScript classes: Import from
uimf-corefor type safety - Component registry pattern: Map component types to UI components
- Handle unknown types gracefully: Provide fallback components or error states
- Respect field metadata: Honor
hidden,required,orderIndexproperties - Implement event handlers: Support the event handler system for dynamic behavior
- Custom properties documentation: Document what custom properties your components expect
- Validate on client: Use
requiredand other metadata for client-side validation - Preserve type information: The
typeproperty determines which component to render
Testing Client Integration
Next Steps
- Explore the uimf-svelte reference implementation
- Learn how to create custom components on the server
- Understand metadata factories for complex metadata
- Review dependency injection patterns