Coder Social home page Coder Social logo

itty-durable-example's Introduction

itty-durable Example

This is an example showing general usage of itty-durable (simplification of Cloudflare Durable Objects). The only two files to note are Counter.js (the Durable Object) and index.js (the Worker index). Beyond that, you may notice some slight differences to the wrangler.toml file to support ES module builds (required for Durable objects), and a slightly different signature at the bottom of index.js. Hit me up on Twitter @kevinrwhitley (or the Cloudflare workers discord, #durable-objects channel) with any questions!

Getting started:

  1. clone repo
  2. npm install
  3. rename wrangler.toml.example to wrangler.toml and inject your own endpoints/account/zone
  4. wrangler publish --new-class Counter (first time publishing)
  5. wrangler publish (subsequent times)

Example endpoint usage (with output):

// GET https://example.com/counter/reset
{
  "created": "2021-04-13T17:33:45.097Z",
  "counter": 0,
  "modified": "2021-04-13T19:31:15.668Z"
}

// GET https://example.com/counter/do-stuff
// GET https://example.com/counter/do-stuff
{
"created": "2021-04-13T17:33:45.097Z",
"counter": 6,
"modified": "2021-04-13T19:31:52.770Z"
}

// GET https://example.com/counter/value
6

// https://example.com/counter/parsed
Counter value 6 last changed at 2021-04-13T19:31:52.770Z

// GET https://example.com/counter/set/foo/bar
{
  "counter": 6,
  "created": "2021-04-13T17:33:45.097Z",
  "modified": "2021-04-13T20:45:58.892Z",
  "foo": "bar"
}

// GET https://example.com/counter/increment
{
  "counter": 7,
  "created": "2021-04-13T17:33:45.097Z",
  "modified": "2021-04-13T20:45:58.892Z",
  "foo": "bar"
}

// GET https://example.com/counter/add/40/2
42

itty-durable-example's People

Contributors

kwhitley avatar

Stargazers

Paul Barrass avatar Jeff Hampton avatar Matthias Fostel avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.