{"id":13469608,"url":"https://github.com/lukeed/worktop","last_synced_at":"2025-05-14T12:11:33.172Z","repository":{"id":37462035,"uuid":"253371061","full_name":"lukeed/worktop","owner":"lukeed","description":"The next generation web framework for Cloudflare Workers","archived":false,"fork":false,"pushed_at":"2024-01-19T00:24:48.000Z","size":402,"stargazers_count":1672,"open_issues_count":20,"forks_count":44,"subscribers_count":26,"default_branch":"master","last_synced_at":"2025-05-12T16:13:06.579Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lukeed.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null},"funding":{"github":"lukeed"}},"created_at":"2020-04-06T01:51:02.000Z","updated_at":"2025-05-11T01:59:11.000Z","dependencies_parsed_at":"2024-04-23T08:06:42.391Z","dependency_job_id":null,"html_url":"https://github.com/lukeed/worktop","commit_stats":{"total_commits":221,"total_committers":6,"mean_commits":"36.833333333333336","dds":"0.022624434389140302","last_synced_commit":"e3a44ba8cd34d7fa6849f98d4fb8dae37afdb404"},"previous_names":[],"tags_count":41,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fworktop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fworktop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fworktop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fworktop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lukeed","download_url":"https://codeload.github.com/lukeed/worktop/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254006532,"owners_count":21998451,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T15:01:46.663Z","updated_at":"2025-05-14T12:11:28.159Z","avatar_url":"https://github.com/lukeed.png","language":"TypeScript","readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"logo.png\" alt=\"worktop\" width=\"620\" /\u003e\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://npmjs.org/package/worktop\"\u003e\n    \u003cimg src=\"https://badgen.now.sh/npm/v/worktop\" alt=\"version\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/lukeed/worktop/actions?query=workflow%3ACI\"\u003e\n    \u003cimg src=\"https://github.com/lukeed/worktop/workflows/CI/badge.svg?event=push\" alt=\"CI\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://npmjs.org/package/worktop\"\u003e\n    \u003cimg src=\"https://badgen.now.sh/npm/dm/worktop\" alt=\"downloads\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://packagephobia.now.sh/result?p=worktop\"\u003e\n    \u003cimg src=\"https://packagephobia.now.sh/badge?p=worktop\" alt=\"install size\" /\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003eThe next generation web framework for Cloudflare Workers\u003c/div\u003e\n\n## Features\n\n* Super [lightweight](https://npm.anvaka.com/#/view/2d/worktop)\n* First-class TypeScript support\n* Custom Middleware Support\n* Well-organized submodules for à la carte functionality\u003csup\u003e*\u003c/sup\u003e\n* Includes Router with support for pattern definitions\n* Familiar Request-Response handler API\n* Supports `async`/`await` handlers\n* Fully treeshakable\n\n\u003e \u003csup\u003e*\u003c/sup\u003e_More to come!_\n\n## Install\n\n```\n$ npm install --save worktop\n```\n\n## Usage\n\n\u003e Check out [`/examples`](/examples) for a list of working demos!\n\n```ts\nimport { Router } from 'worktop';\nimport * as Cache from 'worktop/cache';\nimport { uid as toUID } from 'worktop/utils';\nimport { read, write } from 'worktop/kv';\nimport type { KV } from 'worktop/kv';\n\ndeclare var DATA: KV.Namespace;\n\ninterface Message {\n  id: string;\n  text: string;\n  // ...\n}\n\n// Initialize\nconst API = new Router();\n\n\nAPI.add('GET', '/messages/:id', async (req, res) =\u003e {\n  // Pre-parsed `req.params` object\n  const key = `messages::${req.params.id}`;\n\n  // Assumes JSON (can override)\n  const message = await read\u003cMessage\u003e(DATA, key);\n\n  // Alter response headers directly\n  res.setHeader('Cache-Control', 'public, max-age=60');\n\n  // Smart `res.send()` helper\n  // ~\u003e automatically stringifies JSON objects\n  // ~\u003e auto-sets `Content-Type` \u0026 `Content-Length` headers\n  res.send(200, message);\n});\n\n\nAPI.add('POST', '/messages', async (req, res) =\u003e {\n  try {\n    // Smart `req.body` helper\n    // ~\u003e parses JSON header as JSON\n    // ~\u003e parses form-like header as FormData, ...etc\n    var input = await req.body\u003cMessage\u003e();\n  } catch (err) {\n    return res.send(400, 'Error parsing request body');\n  }\n\n  if (!input || !input.text.trim()) {\n    return res.send(422, { text: 'required' });\n  }\n\n  const value: Message = {\n    id: toUID(16),\n    text: input.text.trim(),\n    // ...\n  };\n\n  // Assumes JSON (can override)\n  const key = `messages::${value.id}`;\n  const success = await write\u003cMessage\u003e(DATA, key, value);\n  //    ^ boolean\n\n  // Alias for `event.waitUntil`\n  // ~\u003e queues background task (does NOT delay response)\n  req.extend(\n    fetch('https://.../logs', {\n      method: 'POST',\n      headers: { 'content-type': 'application/json '},\n      body: JSON.stringify({ success, value })\n    })\n  );\n\n  if (success) res.send(201, value);\n  else res.send(500, 'Error creating record');\n});\n\n\nAPI.add('GET', '/alive', (req, res) =\u003e {\n  res.end('OK'); // Node.js-like `res.end`\n});\n\n\n// Attach \"fetch\" event handler\n// ~\u003e use `Cache` for request-matching, when permitted\n// ~\u003e store Response in `Cache`, when permitted\nCache.listen(API.run);\n```\n\n## API\n\n### Module: `worktop`\n\n\u003e [View `worktop` API documentation](/src/router.d.ts)\n\u003c!-- \u003e [View `worktop` API documentation](/docs/module.router.md) --\u003e\n\nThe main module – concerned with routing. \u003cbr\u003eThis is core of most applications. Exports the [`Router`](/src/router.d.ts#L66) class.\n\n### Module: `worktop/kv`\n\n\u003e [View `worktop/kv` API documentation](/src/kv.d.ts)\n\u003c!-- \u003e [View `worktop/kv` API documentation](/docs/module.kv.md) --\u003e\n\nThe `worktop/kv` submodule contains all classes and utilities related to [Workers KV](https://www.cloudflare.com/products/workers-kv/).\n\n### Module: `worktop/cache`\n\n\u003e [View `worktop/cache` API documentation](/src/cache.d.ts)\n\u003c!-- \u003e [View `worktop/cache` API documentation](/docs/module.cache.md) --\u003e\n\nThe `worktop/cache` submodule contains all utilities related to [Cloudflare's Cache](https://developers.cloudflare.com/workers/learning/how-the-cache-works).\n\n### Module: `worktop/request`\n\n\u003e [View `worktop/request` API documentation](/src/request.d.ts)\n\u003c!-- \u003e [View `worktop/request` API documentation](/docs/module.request.md) --\u003e\n\nThe `worktop/request` submodule contains the [`ServerRequest`](/src/request.d.ts#L117) class, which provides an interface similar to the request instance(s) found in most other Node.js frameworks.\n\n\u003e **Note:** This module is used internally and will (very likely) never be imported by your application.\n\n### Module: `worktop/response`\n\n\u003e [View `worktop/response` API documentation](/src/response.d.ts)\n\u003c!-- \u003e [View `worktop/response` API documentation](/docs/module.response.md) --\u003e\n\nThe `worktop/response` submodule contains the [`ServerResponse`](/src/response.d.ts#L6) class, which provides an interface similar to the [`IncomingMessage`](https://nodejs.org/api/http.html#http_class_http_incomingmessage) (aka, \"response\") object that Node.js provides.\n\n\u003e **Note:** This module is used internally and will (very likely) never be imported by your application.\n\n### Module: `worktop/base64`\n\n\u003e [View `worktop/base64` API documentation](/src/base64.d.ts)\n\u003c!-- \u003e [View `worktop/base64` API documentation](/docs/module.base64.md) --\u003e\n\nThe `worktop/base64` submodule contains a few utilities related to the [Base 64 encoding](https://tools.ietf.org/html/rfc4648#section-4).\n\n### Module: `worktop/cookie`\n\n\u003e [View `worktop/cookie` API documentation](/src/cookie.d.ts)\n\u003c!-- \u003e [View `worktop/cookie` API documentation](/docs/module.cookie.md) --\u003e\n\nThe `worktop/cookie` submodule contains `parse` and `stringify` utilities for dealing with cookie header(s).\n\n### Module: `worktop/cors`\n\n\u003e [View `worktop/cors` API documentation](/src/cors.d.ts)\n\u003c!-- \u003e [View `worktop/cors` API documentation](/docs/module.cors.md) --\u003e\n\nThe `worktop/cors` submodule offers utilities for dealing with [Cross-Origin Resource Sharing (CORS)](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) headers.\n\n### Module: `worktop/crypto`\n\n\u003e [View `worktop/crypto` API documentation](/src/crypto.d.ts)\n\u003c!-- \u003e [View `worktop/crypto` API documentation](/docs/module.crypto.md) --\u003e\n\nThe `worktop/crypto` submodule is a collection of cryptographic functionalities.\n\n### Module: `worktop/utils`\n\n\u003e [View `worktop/utils` API documentation](/src/utils.d.ts)\n\u003c!-- \u003e [View `worktop/utils` API documentation](/docs/module.utils.md) --\u003e\n\nThe `worktop/utils` submodule is a collection of standalone, general-purpose utilities that you may find useful. These may include – but are not limited to – hashing functions and unique identifier generators.\n\n### Module: `worktop/ws`\n\n\u003e [View `worktop/ws` API documentation](/src/ws.d.ts)\n\u003c!-- \u003e [View `worktop/ws` API documentation](/docs/module.ws.md) --\u003e\n\nThe `worktop/ws` submodule contains the [`WebSocket`](/src/ws.d.ts#L18) and [`WebSocketPair`](/src/ws.d.ts#L4) class definitions, as well as two middleware handlers for validating and/or setting up a [`SocketHandler`](/src/ws.d.ts#L38) for the WebSocket connection.\n\n\n## License\n\nMIT © [Luke Edwards](https://lukeed.com)\n","funding_links":["https://github.com/sponsors/lukeed"],"categories":["TypeScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukeed%2Fworktop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flukeed%2Fworktop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukeed%2Fworktop/lists"}