{"id":15046933,"url":"https://github.com/kakengloh/bagel","last_synced_at":"2025-10-28T11:17:06.818Z","repository":{"id":58898615,"uuid":"533825011","full_name":"kakengloh/bagel","owner":"kakengloh","description":"Tiny and expressive web framework for Bun.js","archived":false,"fork":false,"pushed_at":"2023-01-12T06:20:18.000Z","size":150,"stargazers_count":43,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-01T22:03:35.129Z","etag":null,"topics":["bagel","https","javascript","microservice","nodejs","server","typescript","web"],"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/kakengloh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-09-07T15:24:29.000Z","updated_at":"2024-09-02T06:57:55.000Z","dependencies_parsed_at":"2023-02-09T10:31:41.583Z","dependency_job_id":null,"html_url":"https://github.com/kakengloh/bagel","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kakengloh%2Fbagel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kakengloh%2Fbagel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kakengloh%2Fbagel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kakengloh%2Fbagel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kakengloh","download_url":"https://codeload.github.com/kakengloh/bagel/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238768422,"owners_count":19527197,"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":["bagel","https","javascript","microservice","nodejs","server","typescript","web"],"created_at":"2024-09-24T20:53:46.393Z","updated_at":"2025-10-28T11:17:01.776Z","avatar_url":"https://github.com/kakengloh.png","language":"TypeScript","funding_links":[],"categories":["Extensions"],"sub_categories":["Frameworks"],"readme":"\u003ch1\u003e\r\n  \u003cimg width=\"40\" align=\"left\" alt=\"Bagel.js logo\" src=\"https://user-images.githubusercontent.com/40446720/189159247-721df1ee-4dae-44bf-8693-257d0b78c576.svg\" /\u003e\r\n  \u003cspan\u003eBagel\u003c/span\u003e\r\n\u003c/h1\u003e\r\n\r\n![Bagel CI status](https://github.com/kakengloh/bagel/actions/workflows/ci.yml/badge.svg)\r\n![Bagel NPM version](https://img.shields.io/npm/v/@kakengloh/bagel)\r\n\r\n**Bagel** is a tiny and expressive web framework for [Bun.js](https://bun.sh/) for building web APIs.\r\n\r\nInspired by [Express.js](https://expressjs.com/) and [Koa.js](https://koajs.com/).\r\n\r\nHere we treat **Typescript** as first class citizen, hence every request handler supports **generic** and you may specify your own typing of request params, query, body and response body.\r\n\r\n## Contents\r\n\r\n- [Features](#features)\r\n- [Examples](#examples)\r\n- [Benchmark](#benchmark)\r\n\r\n## Features\r\n\r\n✅ Routing\r\n\r\n✅ Middlewares\r\n\r\n✅ JSON parsing\r\n\r\n✅ Strongly typed route handlers\r\n\r\n## Installation\r\n\r\n```bash\r\nbun add @kakengloh/bagel\r\n```\r\n\r\n## Examples\r\n\r\n### Basic\r\n\r\n```typescript\r\nimport { Bagel, Router } from '@kakengloh/bagel';\r\n\r\nconst app = new Bagel();\r\n\r\napp.get('/', async (req, res) =\u003e res.send('Hello from Bagel.js!'));\r\n\r\napp.listen(3000);\r\n```\r\n\r\n### Router\r\n\r\n```typescript\r\nimport { Bagel, Router } from '@kakengloh/bagel';\r\n\r\n// Create items router\r\nconst items = new Router();\r\nitems.get('/', async (req, res) =\u003e res.json({ items: [] }));\r\n\r\n// Create v1 router\r\nconst v1 = new Router();\r\n// Mount items router to v1 router\r\nv1.mount('/items', items);\r\n\r\nconst app = new Bagel();\r\n\r\n// Mount v1 router to app\r\napp.mount('/v1', v1);\r\n\r\napp.listen(3000);\r\n```\r\n\r\n### Middleware\r\n\r\n```typescript\r\nimport { Bagel, Router } from '@kakengloh/bagel';\r\n\r\nconst app = new Bagel();\r\n\r\n// Before middleware\r\napp.use(async (req, res, next) =\u003e {\r\n  console.log('Before');\r\n});\r\n\r\n// Route handler\r\napp.get('/', async (req, res) =\u003e res.send('Hello from Bagel.js!'));\r\n\r\n// After middleware\r\napp.use(async (req, res, next) =\u003e {\r\n  console.log('After');\r\n});\r\n\r\napp.listen(3000);\r\n```\r\n\r\n### Strong typing\r\n\r\n```typescript\r\nimport { Bagel, Handler } from '@kakengloh/bagel';\r\n\r\n// Entity\r\ninterface Bread {\r\n  bakeryId: string;\r\n  name: string;\r\n  price: number;\r\n}\r\n\r\n// Path parameters\r\ninterface PathParams {\r\n  bakeryId: string;\r\n}\r\n\r\n// Query parameters\r\ntype QueryParams = Record\u003cstring, unknown\u003e;\r\n\r\n// Request body\r\ntype RequestBody = Bread;\r\n\r\n// Response body\r\ninterface ResponseBody {\r\n  bread: Bread;\r\n}\r\n\r\n// Route handler with all types specified\r\nconst createBread: Handler\u003c\r\n  PathParams,\r\n  QueryParams,\r\n  RequestBody,\r\n  ResponseBody\r\n\u003e = async (req, res) =\u003e {\r\n  const { name, price } = req.body; // Typed inferred\r\n  const { bakeryId } = req.params; // Typed inferred\r\n\r\n  const bread: Bread = {\r\n    bakeryId,\r\n    name,\r\n    price,\r\n  };\r\n\r\n  return res.json({ bread }); // Typed checked\r\n};\r\n\r\nconst app = new Bagel();\r\napp.post('/bakeries/:bakeryId/breads', createBread);\r\n\r\napp.listen(3000);\r\n```\r\n\r\n### Error handling\r\n\r\n```typescript\r\nimport { Bagel } from '@kakengloh/bagel';\r\n\r\nconst app = new Bagel({\r\n  // Every error thrown will go through this function\r\n  // Here you can return a custom response\r\n  error: async (res, err) =\u003e {\r\n    return res.status(400).json({ error: 'Bad request' });\r\n  },\r\n});\r\n\r\napp.get('/error', async () =\u003e {\r\n  throw new Error('Some error');\r\n});\r\n\r\napp.listen(3000);\r\n```\r\n\r\n## Benchmark\r\n\r\nBelow is a simple benchmark of **Bagel.js** and **Express.js** conducted on my machine using [autocannon](https://github.com/mcollina/autocannon) (12 threads, 500 concurrent connections, 10 seconds)\r\n\r\n\u003e The output shows that Bagel.js can handle ~2.67x more requests than Express.js\r\n\r\n\u003cimg width=\"612\" alt=\"Screenshot 2022-09-09 at 9 19 02 PM\" src=\"https://user-images.githubusercontent.com/40446720/189360153-4178e19d-0d80-40b0-ad2e-404bec214e8b.png\"\u003e\r\n\u003cimg width=\"602\" alt=\"Screenshot 2022-09-09 at 9 15 42 PM\" src=\"https://user-images.githubusercontent.com/40446720/189360193-f5a68eb0-535b-4f0d-bde0-0cf680477fac.png\"\u003e\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkakengloh%2Fbagel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkakengloh%2Fbagel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkakengloh%2Fbagel/lists"}