-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackage.go
More file actions
64 lines (64 loc) · 2.52 KB
/
package.go
File metadata and controls
64 lines (64 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Package hmc provides types for building HATEOAS-driven REST APIs with
// progressive enhancement.
//
// Each type represents a hypermedia control—a semantic element that guides
// client state transitions. These controls can be serialized as JSON, XML,
// or wrapped in HTML templates depending on the client's capabilities.
//
// # Philosophy
//
// Traditional REST APIs serve data (JSON) and leave state transitions to
// out-of-band documentation. HATEOAS APIs serve hypermedia—data enriched
// with the controls needed to interact with it. This library provides the
// building blocks for those controls.
//
// The types in hmc are deliberately minimal, focusing on the semantic
// layer rather than presentation. They describe WHAT actions are available
// and HOW to invoke them, not how they should be styled or rendered.
//
// # Progressive Enhancement
//
// The same endpoint can serve multiple representations:
//
// - JSON: Machine-readable, suitable for scripts and traditional API clients
// - XML: Human-readable structure for CLI tools (curl, HTTPie + xmllint)
// - HTML: Browser-ready interfaces when wrapped with your templates
//
// This enables a "write once, serve many" approach where a single handler
// can satisfy browsers, CLIs, and programmatic clients through content
// negotiation.
//
// # Usage
//
// Types are designed to be embedded in your domain structs:
//
// type LoginPage struct {
// LoginForm hmc.Form[struct {
// Username hmc.Input
// Password hmc.Input
// Submit hmc.Submit
// }]
// RegisterLink hmc.Link
// }
//
// Marshal to JSON for API clients, XML for CLI tools, or wrap in HTML
// templates for browsers. Examples at ./examples/templates.
//
// Input validation is minimal and extensible—Validate() checks Required
// and MinLength, matching basic browser behavior. Extend by inspecting
// Input.Value and setting Input.Error for domain-specific rules.
//
// # Pairs Well With
//
// This library pairs naturally with github.com/Teajey/rsvp, which provides
// HTTP handlers with ergonomic content negotiation, making it easy to serve
// the same semantic data in multiple formats based on Accept headers.
//
// # What This Is Not
//
// This is not a complete HTML generation framework. You bring your own
// templates for presentation (you should use the examples as a starting point).
// This is not a client-side form library—it's server-side semantics.
// This is not a validation framework—it provides minimal checks and extension
// points for your domain rules.
package hmc