A tiny Python/ASGI backend for HTML and JavaScript apps.
Roll a route. Pass some JSON. Ship that shit.
$ git clone https://gitman.io/git/patx/wred
$ cd wred
$ uv sync
$ cat > app.py <<'EOF'
from wred import App
app = App()
@app.route('/')
async def index(request):
return await app.static('index.html', root='static')
@app.route('/data')
async def populate(request):
return [{"name": "Jim", "email": "jim@gmail.com"}]
EOF
$ mkdir -p static
$ cat > static/index.html <<'EOF'
<ul id="users"></ul>
<script type="module">
const users = await fetch('/data').then(r => r.json());
for (const user of users) {
const li = document.createElement('li');
li.textContent = `${user.name} (${user.email})`;
document.querySelector('#users').append(li);
}
</script>
EOF
$ uv run granian --interface asginl app:app
