Skip to content

Latest commit

 

History

History
51 lines (36 loc) · 1.55 KB

README.md

File metadata and controls

51 lines (36 loc) · 1.55 KB

Hono for Durable Object

Hono DO is a wrapper of Cloudflare Workers ' Durable Object, designed for Hono.

Important

Cloudflare released RPC feature, which is a better way to communicate between Durable Objects. This library was developed to improve the developer experience for Durable Objects when RPC was not yet available. So, please consider it before using this library.

$ npm install hono-do

Usage

export const Counter = generateHonoObject("/counter", async (app, state) => {
  const { storage } = state;
  let value = (await storage.get<number>("value")) ?? 0;

  app.post("/increment", (c) => {
    storage.put("value", value++);
    return c.text(value.toString());
  });

  app.post("/decrement", (c) => {
    storage.put("value", value--);
    return c.text(value.toString());
  });

  app.get("/", (c) => {
    return c.text(value.toString());
  });
});

You want to find more? Check out the examples!

Support

License

MIT

Contributing

This project is open for contributions. Feel free to open an issue or a pull request! Contributing Guide for more information.