{"id":22570827,"url":"https://github.com/happer64bit/bunwork","last_synced_at":"2025-09-22T08:54:22.804Z","repository":{"id":261779199,"uuid":"885341482","full_name":"happer64bit/Bunwork","owner":"happer64bit","description":"A Lightweight Backend Framework For Bun","archived":false,"fork":false,"pushed_at":"2025-01-30T12:42:40.000Z","size":25,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-19T07:46:26.510Z","etag":null,"topics":["api","backend","bun","framework","javascript","server","tools","typescript"],"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/happer64bit.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":"2024-11-08T12:00:22.000Z","updated_at":"2025-03-12T11:12:34.000Z","dependencies_parsed_at":"2024-11-08T12:10:21.482Z","dependency_job_id":"97a7d6cf-7243-41dc-9671-9ea711942baf","html_url":"https://github.com/happer64bit/Bunwork","commit_stats":null,"previous_names":["happer64bit/bunwork"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/happer64bit%2FBunwork","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/happer64bit%2FBunwork/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/happer64bit%2FBunwork/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/happer64bit%2FBunwork/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/happer64bit","download_url":"https://codeload.github.com/happer64bit/Bunwork/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248123955,"owners_count":21051563,"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":["api","backend","bun","framework","javascript","server","tools","typescript"],"created_at":"2024-12-08T01:13:32.260Z","updated_at":"2025-09-22T08:54:17.738Z","avatar_url":"https://github.com/happer64bit.png","language":"TypeScript","funding_links":[],"categories":["Extensions"],"sub_categories":["Frameworks"],"readme":"# BunWork `Simplicity == Joy`\n\n_Bun refers to the Just Bun runtime, while Work refers to the framework._\n\nBunwork is just a `Bun.serve` based but make it easier for developer, designed to simplify HTTP server setup and routing for developers.\n\n## Features\n\n* Middleware support\n* Route definition with dynamic parameters\n* Blueprint-based routing (modular route groups)\n* Easy integration with `Bun.serve`\n\n## Installation\n\nTo use Bunwork, you need to have [Bun](https://bun.sh) installed.\n\nTo install Bunwork in your project, you can simply add it to your codebase as follows:\n\n```bash\nbun add bunwork\n```\n\n## Usage\n\n### 1. Create a Server\n\n```javascript\nimport Bunwork from \"bunwork\";\n\nconst app = new Bunwork();\n\n// Define middleware\napp.middleware((req, res, next) =\u003e {\n    console.log(`Request made to ${req.url}`);\n    next();  // Call next() to continue processing the request\n});\n\n// Define GET route\napp.get('/hello/:name', (req) =\u003e {\n    const url = new URL(req.url);\n    const id = url.pathname.split('/')[2];\n    \n    return new Response(`Hello, ${name}!`);\n});\n\n// Define POST route\napp.post('/data', (req) =\u003e {\n    // Process POST data here\n    return new Response('Data received');\n});\n\n// Start the server\napp.listen(3000, () =\u003e {\n    console.log(\"Server is running on port 3000\");\n});\n```\n\n### 2. Define Dynamic Routes\n\nDynamic routes allow you to capture variables from the URL path. In the example below, the :name part of the URL is a dynamic parameter.\n\n```javascript\napp.get('/hello/:name', (req) =\u003e {\n    const { name } = req.params;  // Extract dynamic parameter\n    return new Response(`Hello, ${name}!`);\n});\n```\n\nFor instance, requesting `/hello/john` will return `\"Hello, john!\"`.\n\n### 3. Using Blueprints\n\nBlueprints allow you to group routes and middlewares into modular sections with a common prefix.\n\n```javascript\nimport { Router } from \"bunwork\";\n\n// Create a new blueprint with a prefix\nconst userBlueprint = new Router('/users');\n\n// Define routes within the blueprint\nuserBlueprint.get('/:id', (req) =\u003e {\n    const { id } = req.params;\n    return new Response(`User ID: ${id}`);\n});\n\nuserBlueprint.post('/:id/update', (req) =\u003e {\n    const { id } = req.params;\n    return new Response(`User ${id} updated`);\n});\n\n// Register the blueprint to the main app\n\nuserBlueprint.applyTo(server);\n```\n\nThis will allow you to have routes like `/users/1` and `/users/1/update`.\n\n### 4. Middleware\n\nMiddleware functions are executed for every request. You can use them to log requests, handle authentication, or manipulate request/response objects before they reach your route handler.\n\n```javascript\napp.middleware((req, res, next) =\u003e {\n    console.log(`Request received at ${req.url}`);\n    next();  // Proceed to the next middleware or route handler\n});\n```\n\n### 5. Handling Errors\n\nYou can handle errors gracefully by adding custom error handling middleware.\n\n```javascript\napp.middleware((req, res, next) =\u003e {\n    try {\n        next();\n    } catch (err) {\n        console.error('Error occurred:', err);\n        return new Response('Internal Server Error', { status: 500 });\n    }\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhapper64bit%2Fbunwork","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhapper64bit%2Fbunwork","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhapper64bit%2Fbunwork/lists"}