Workloads
Backends & REST APIs
Serve HTTP APIs and frontends from a generated app with any framework that speaks fetch.
Prefer to read code? Clone the example repository. View on GitHub
Example generated code
import { Hono } from "hono";
const app = new Hono();
// Serve the application's frontend.
app.get("/", (c) => {
return c.html(`<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Hello from Dynamic Apps</title>
</head>
<body>
<main>
<h1>Hello from Dynamic Apps</h1>
<p>This HTML is served by an HTTP app running inside agentOS.</p>
<p><a href="./api/hello">Call the JSON API</a></p>
</main>
</body>
</html>`);
});
// Serve a REST API request from the same application.
app.get("/api/hello", (c) => {
return c.json({ message: "Hello from Dynamic Apps" });
});
export default app;
Deploy and route
Deploy the directory and every route the app defines is served under
/apps/:appId on your routing server:
import { serve } from "@hono/node-server";
import { appsRouter } from "@rivet-dev/dynamic-apps";
import { Hono } from "hono";
const server = new Hono();
// This is how the Rivet control plane communicates with your backend.
server.all("/api/rivet/*", (c) => appsRouter.fetch(c.req.raw));
// Mount every deployed application at /apps/:appId.
server.route("/apps", appsRouter);
// Serve the host router over HTTP.
serve({
fetch: server.fetch,
port: 3000,
});
See Route for how requests reach the app and Deploy for builds and releases.