{"id":15314254,"url":"https://github.com/barelyhuman/tiny-use","last_synced_at":"2025-04-15T02:12:53.535Z","repository":{"id":234975444,"uuid":"789842556","full_name":"barelyhuman/tiny-use","owner":"barelyhuman","description":"The tiniest middleware library for node's standard HTTP library and the Fetch API","archived":false,"fork":false,"pushed_at":"2024-09-09T12:47:18.000Z","size":76,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-15T02:12:48.890Z","etag":null,"topics":["async","http","middleware","node"],"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/barelyhuman.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-04-21T17:46:33.000Z","updated_at":"2024-09-10T05:13:12.000Z","dependencies_parsed_at":"2024-04-23T17:39:04.608Z","dependency_job_id":null,"html_url":"https://github.com/barelyhuman/tiny-use","commit_stats":null,"previous_names":["barelyhuman/tiny-use"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barelyhuman%2Ftiny-use","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barelyhuman%2Ftiny-use/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barelyhuman%2Ftiny-use/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barelyhuman%2Ftiny-use/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/barelyhuman","download_url":"https://codeload.github.com/barelyhuman/tiny-use/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248991558,"owners_count":21194894,"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":["async","http","middleware","node"],"created_at":"2024-10-01T08:44:52.800Z","updated_at":"2025-04-15T02:12:53.519Z","avatar_url":"https://github.com/barelyhuman.png","language":"TypeScript","readme":"# @barelyhuman/tiny-use\n\n\u003e The tiniest middleware library for node's HTTP\n\n![Coverage](./docs/badges.svg)\n\nInvisible if you squint hard enough\n\n- [@barelyhuman/tiny-use](#barelyhumantiny-use)\n  - [Why ?](#why-)\n  - [Installation](#installation)\n  - [Usage](#usage)\n    - [Node HTTP API](#node-http-api)\n      - [Ecosystem](#ecosystem)\n    - [Fetch Compliant API](#fetch-compliant-api)\n  - [License](#license)\n\n## Why ?\n\nI've written this in my experimentals sink for over 1.5 years now, the first\npublic version of the same is available here\n[barelyhuman/http/middleware](https://github.com/barelyhuman/http/blob/b7ee273a0ba98bebd857ad7e8ee4324970629eb2/src/middleware.js).\n\nI made it to be small and contained to reduce the middleware's load on node's\nserver.\n\nWith respect to:\n\n- **Performace** - It's linear and basically depends on what load you add in\n  your actual middleware since it itself has no overhead.\n- **Reason** - Like everything else, I've written it more than once and reached\n  a point of saturation where I don't want to reduce it's size in terms of code\n  and functionality.\n- **Stability** - The API isn't going to change since it's very basic and ties\n  to the Node API so unless that changes, makes no sense for this to change\n\n## Installation\n\n```sh\n; npm i --save @barelyhuman/tiny-use\n```\n\n## Usage\n\n### Node HTTP API\n\nTo use with the default `node:http`/`http` API, you use it just like any other\nexpress js middleware, the difference being that the middleware now supports\nasync flow\n\n```js\nimport http from 'node:http'\nimport { use } from '@barelyhuman/tiny-use'\n\nhttp.createServer(\n  use(\n    async (req, res, next) =\u003e {\n      req.value = 1\n      await next()\n      console.log({\n        value: req.value,\n      })\n    },\n    async (req, res, next) =\u003e {\n      req.value = 2\n      res.end('Final Message')\n      return\n    }\n  )\n)\n```\n\n#### Ecosystem\n\nYou don't have to rebuild an ecosystem, most of what `connect` has and what\nexpress uses should be usable.\n\n### Fetch Compliant API\n\nIf you work with network functions that are more inclined to the Fetch API\nstandard and you need to use common middleware instead of manually calling them\nin each function call, you can do so by making minor modifications to the import\n\n```js\nimport { use } from '@barelyhuman/tiny-use/fetch'\n\nconst withMiddleware = use(\n  req =\u003e {\n    req.userId = 1\n  },\n  req =\u003e {\n    return new Response(req.userId)\n  }\n)\n\nexport default {\n  fetch: withMiddleware,\n}\n```\n\n\u003e [!NOTE]\n\u003e When using the fetch based API, you might need to also add a bundling step if\n\u003e the tool you use doesn't do the bundling for you\n\n## License\n\n[MIT](/LICENSE)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbarelyhuman%2Ftiny-use","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbarelyhuman%2Ftiny-use","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbarelyhuman%2Ftiny-use/lists"}