OverviewFilesCommitsIssuesDocsReleasesPeers

hyper-web-ui commits / 31972d5

README: the repo had none
Exports and signatures taken from index.js and lib/, not from memory. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
31972d5b420db2e9b12ac713026b6871e4a6f1cd
by plankatron <fleeky@gmail.com> · 2026-09-10T15:43:12.000Z

Changed files (1) +81 -0

README.md +81 -0
……@@ -0,0 +1,81 @@
1# hyper-web-ui
2
3A shared web framework for P2P apps — JSON API router, SSR + SPA serving, identity client.
4
5Small and dependency-light (one runtime dep, `hypercore-crypto`). It is the HTTP layer several
6of the P2P daemons in this tree serve their web UI through, rather than each growing its own.
7
8## Install
9
10```sh
11npm install hyper-web-ui
12```
13
14## Usage
15
16```js
17import { Router, json, html, serveStatic, authMiddleware } from 'hyper-web-ui'
18
19const router = new Router('/api', { cors: true })
20
21router.get('/repos/:name', async (req, res, params) => {
22 json(res, await lookup(params.name))
23})
24
25router.post('/repos', async (req, res) => {
26 const body = await readJson(req)
27 json(res, await create(body), 201)
28})
29```
30
31## API
32
33#### `new Router(prefix = '', { cors, corsOrigin })`
34
35`.get()`, `.post()`, `.patch()`, `.del()` — each takes `(pattern, handler, opts)`. Patterns
36support `:params`.
37
38#### Responses
39
40```js
41json(res, data, status = 200, corsOrigin = null)
42html(res, content, status = 200, corsOrigin = null)
43jsonCached(res, data, maxAge = 10)
44cacheControl(res, opts)
45withEtag(req, res, etag, sendFn) // 304 when the etag matches
46```
47
48#### Requests
49
50```js
51await readBody(req)
52await readJson(req)
53parsePagination(query, opts) // -> { page, pageSize, offset }
54```
55
56#### `authMiddleware(opts)`
57
58Identity-based auth for the router.
59
60#### `serveStatic(webDir, opts)`
61
62Serve a directory, with SPA fallback.
63
64#### Rendering
65
66```js
67renderMarkdown(text)
68renderDiff(patch)
69renderCode(content, opts)
70renderPagination(total, page, pageSize, baseUrl)
71renderBranchSelector(branches, current, baseUrl)
72detectLanguage(filename)
73```
74
75The `renderDiff` / `renderBranchSelector` / `detectLanguage` set exists because this was
76factored out of a git forge UI; they are useful beyond that but that is where the shape comes
77from.
78
79## License
80
81Not yet declared.