hono
server側のコードを書くと、client側のREST API wrapperを作れる code:exaple.ts
import { Hono } from "jsr:@hono/hono@4";
import type { BasePage, Page } from "jsr:@cosense/types@0.10/rest";
import { hc } from "jsr:@hono/hono@4/client";
const pages = new Hono()
.get(
"/:project",
(ctx) =>
ctx.json({
projectName: ctx.req.param("project"),
skip: parseInt(ctx.req.query("skip") ?? "0"),
limit: parseInt(ctx.req.query("limit") ?? "100"),
count: 23434,
pages: [] as BasePage[],
}),
)
.get(
"/:project/:title",
(ctx) => ctx.json({ title: ctx.req.param("title") } as unknown as Page),
);
const route = new Hono().route("/api/pages", pages);
const client = hc<typeof route>("");
const res = await client.api.pages":project".$get({ param: { project: "takker" },
});
const list = await res.json();
for (const pages of list.pages) {
param: { project: "takker", title: pages.title },
});
console.log((await res.json()).lines.map((line) => line.text).join("\n"));
}
Responseに型をつけたClientResponse<T, U, F>を使っている