{"id":13734672,"url":"https://github.com/lucacasonato/workerkit","last_synced_at":"2025-04-19T12:03:37.569Z","repository":{"id":47944563,"uuid":"192586922","full_name":"lucacasonato/workerkit","owner":"lucacasonato","description":"A library to make writing Cloudflare Workers way nicer","archived":false,"fork":false,"pushed_at":"2023-01-04T23:58:49.000Z","size":1140,"stargazers_count":24,"open_issues_count":12,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-29T07:41:35.001Z","etag":null,"topics":["cloudflare","cloudflare-worker","typescript","workers-kv"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/cf-worker-kit","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/lucacasonato.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-06-18T17:43:48.000Z","updated_at":"2025-02-10T10:03:57.000Z","dependencies_parsed_at":"2023-02-03T00:50:16.125Z","dependency_job_id":null,"html_url":"https://github.com/lucacasonato/workerkit","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucacasonato%2Fworkerkit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucacasonato%2Fworkerkit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucacasonato%2Fworkerkit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucacasonato%2Fworkerkit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lucacasonato","download_url":"https://codeload.github.com/lucacasonato/workerkit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249236955,"owners_count":21235347,"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":["cloudflare","cloudflare-worker","typescript","workers-kv"],"created_at":"2024-08-03T03:00:58.715Z","updated_at":"2025-04-19T12:03:37.540Z","avatar_url":"https://github.com/lucacasonato.png","language":"TypeScript","funding_links":[],"categories":["Tool"],"sub_categories":[],"readme":"# cf-worker-kit\n\n[![GitHub Actions](https://github.com/lucacasonato/workerkit/workflows/ci/badge.svg)](https://github.com/lucacasonato/workerkit/actions)\n\nA library to make writing Cloudflare Workers way nicer. It implements routing and a nice Workers KV API for you. With this library you have to write considerably less boilerplate than a standard Cloudflare Worker.\n\n## installation\n\nInstall by running `npm i cf-worker-kit` or `yarn add cf-worker-kit` then import:\n\n```js\nconst workerkit = require('cf-worker-kit');\n// or\nconst { Worker, Router, API } = require('cf-worker-kit');\n// or\nimport workerkit from 'cf-worker-kit';\n// or\nimport { Worker, Router, API } from 'cf-worker-kit';\n```\n\n## example\n\n```js\n// setup for http handling\nconst worker = new Worker();\nconst router = new Router();\n\n// setup for workers kv\nconst api = new API('cf_account_id', 'cf_api_email', 'cf_api_key');\nconst BOOKS = api.kv.get('kv_namespace_id');\n\n// hello world function\nrouter.any('.*/hello', req =\u003e {\n  return new Response(`Hello from method ${req.method}!`);\n});\n\n// get the IDs of all books in the KV namespace\nrouter.get('.*/books', async () =\u003e {\n  const books = await BOOKS.keys();\n\n  return new Response(books.map(book =\u003e book.name).join(', '));\n});\n\nworker.use(router);\nworker.listen();\n```\n\n## documentation\n\nhttps://workerkit.lcas.dev\n\n## notes on Workers KV\n\nIf you are using KV in your worker only for `get`, `set` and `delete` operations, you should use the [native Worker KV API](https://workers.cloudflare.com/docs/reference/storage/api/#worker-api), because it is considerably faster because it is implemented as a native call in the Cloudflare Worker environment. As more functions become available in the native API, workerkit might start using these.\n\n### using the native KV implemenation with typescript\n\nIf you want to use the Native KV implementation in Cloudflare Workers and you are using TypeScript, then you can use code like the one below to make TS recognize the KV namespace as such.\n\n```typescript\n// in this case the name of the native KV instance is 'BOOKS'.\n\nimport { NativeKV } from 'cf-worker-kit';\n\ndeclare global {\n  const BOOKS: NativeKV;\n}\n```\n\n## soon(tm)\n\n- bulk Workers KV setting and deleting\n- query params in req\n- make KV give better errors\n\n## licence\n\nMIT License\nCopyright (c) 2019 Luca Casonato\nFull licence in the LICENCE file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucacasonato%2Fworkerkit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flucacasonato%2Fworkerkit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucacasonato%2Fworkerkit/lists"}