{"id":15408359,"url":"https://github.com/yusukebe/pico","last_synced_at":"2025-04-10T01:07:45.240Z","repository":{"id":63692700,"uuid":"569723337","full_name":"yusukebe/pico","owner":"yusukebe","description":"Ultra-tiny router for Cloudflare Workers and Deno","archived":false,"fork":false,"pushed_at":"2024-01-28T21:34:46.000Z","size":285,"stargazers_count":185,"open_issues_count":1,"forks_count":6,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-10T01:07:19.082Z","etag":null,"topics":["cloudflare","cloudflare-workers","deno","router","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@picojs/pico","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/yusukebe.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-11-23T13:23:00.000Z","updated_at":"2025-03-31T08:50:51.000Z","dependencies_parsed_at":"2023-12-31T04:19:07.716Z","dependency_job_id":"e660281c-25be-41f0-a68f-3bf1f74e2494","html_url":"https://github.com/yusukebe/pico","commit_stats":{"total_commits":57,"total_committers":3,"mean_commits":19.0,"dds":0.1578947368421053,"last_synced_commit":"69c6ead3db59934359a104a575904e4348c0d35f"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yusukebe%2Fpico","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yusukebe%2Fpico/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yusukebe%2Fpico/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yusukebe%2Fpico/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yusukebe","download_url":"https://codeload.github.com/yusukebe/pico/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248137888,"owners_count":21053775,"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-workers","deno","router","typescript"],"created_at":"2024-10-01T16:33:38.737Z","updated_at":"2025-04-10T01:07:45.218Z","avatar_url":"https://github.com/yusukebe.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# Pico\n\n[![Version](https://img.shields.io/npm/v/@picojs/pico.svg)](https://npmjs.com/package/@picojs/pico)\n[![Bundle Size](https://img.shields.io/bundlephobia/min/@picojs/pico)](https://bundlephobia.com/result?p=@picojs/pico)\n[![Bundle Size](https://img.shields.io/bundlephobia/minzip/@picojs/pico)](https://bundlephobia.com/result?p=@picojs/pico)\n\nPico is an ultra-tiny ([~400 bytes](https://bundlephobia.com/package/@picojs/pico) compressed) router using `URLPattern`.\nPico works on Cloudflare Workers and Deno.\n\n**This project is still experimental. The API might be changed.**\n\n## Install\n\n```\nnpm i @picojs/pico\n// Or\nyarn add @picojs/pico\n```\n\nInstall `@cloudflare/workers-types` for supporting the types.\n\n```\nnpm i -D @cloudflare/workers-types\n// Or\nyarn add -D @cloudflare/workers-types\n```\n\n## Example\n\n```ts\n// index.ts\nimport { Pico } from '@picojs/pico'\n\n// create a router object, `new` is not needed\nconst router = Pico()\n\n// handle a GET request and return a TEXT response\nrouter.get('/', (c) =\u003e new Response('Hello Pico!'))\n\n// capture path parameters and return a JSON response\nrouter.post('/entry/:id', ({ result }) =\u003e {\n  const { id } = result.pathname.groups\n  return Response.json({\n    'your id is': id,\n  })\n})\n\n// return a primitive Response object\nrouter.get('/money', () =\u003e new Response('Payment required', { status: 402 }))\n\n// capture path parameters with RegExp\nrouter.get('/post/:date(\\\\d+)/:title([a-z]+)', ({ result }) =\u003e {\n  const { date, title } = result.pathname.groups\n  return Response.json({ post: { date, title } })\n})\n\n// get query parameters\nrouter.get('/search', ({ result }) =\u003e {\n  const query = new URLSearchParams(result.search.input).get('q')\n  return new Response(`Your query is ${query}`)\n})\n\n// handle a PURGE method and return a Redirect response\nrouter.on('PURGE', '/cache', () =\u003e {\n  return new Response(null, {\n    status: 302,\n    headers: {\n      Location: '/',\n    },\n  })\n})\n\n// get environment variables for Cloudflare Workers\nrouter.get('/secret', ({ env }) =\u003e {\n  console.log(env.TOKEN)\n  return new Response('Welcome!')\n})\n\n// use an executionContext for Cloudflare Workers\nrouter.get('/log', ({ executionContext, req }) =\u003e {\n  executionContext.waitUntil((async () =\u003e console.log(`You access ${req.url.toString()}`))())\n  return new Response('log will be shown')\n})\n\n// return a custom 404 response\nrouter.all('*', () =\u003e new Response('Custom 404', { status: 404 }))\n\n// export the app for Cloudflare Workers\nexport default router\n```\n\n## Develop with Wrangler\n\n```\nwrangler dev index.ts\n```\n\n## Deploy to Cloudflare Workers\n\n```\nwrangler publish index.ts\n```\n\n## Deno\n\n```ts\nimport { serve } from 'https://deno.land/std/http/server.ts'\nimport { Pico } from 'https://esm.sh/@picojs/pico'\n\nconst router = Pico()\nrouter.get('/', () =\u003e new Response('Hi Deno!'))\n\n//...\n\nserve(router.fetch)\n```\n\n```\ndeno run --allow-net pico.ts\n```\n\n## Related projects\n\n- Hono \u003chttps://hono.dev\u003e\n- itty-router \u003chttps://github.com/kwhitley/itty-router\u003e\n\n## Author\n\nYusuke Wada \u003chttps://github.com/yusukebe\u003e\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyusukebe%2Fpico","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyusukebe%2Fpico","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyusukebe%2Fpico/lists"}