{"id":23636910,"url":"https://github.com/serviejs/throwback","last_synced_at":"2025-08-31T11:34:06.662Z","repository":{"id":46945870,"uuid":"58227211","full_name":"serviejs/throwback","owner":"serviejs","description":"An asynchronous middleware pattern","archived":false,"fork":false,"pushed_at":"2023-12-12T07:38:00.000Z","size":1577,"stargazers_count":27,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-14T21:52:58.315Z","etag":null,"topics":["compose","koa","middleware","popsicle","servie"],"latest_commit_sha":null,"homepage":null,"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/serviejs.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":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-05-06T18:32:15.000Z","updated_at":"2024-06-24T07:53:08.000Z","dependencies_parsed_at":"2024-06-18T18:13:28.904Z","dependency_job_id":null,"html_url":"https://github.com/serviejs/throwback","commit_stats":{"total_commits":52,"total_committers":3,"mean_commits":"17.333333333333332","dds":"0.40384615384615385","last_synced_commit":"ce67741e5cfe2110837515b03041de4b4710d758"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serviejs%2Fthrowback","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serviejs%2Fthrowback/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serviejs%2Fthrowback/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serviejs%2Fthrowback/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/serviejs","download_url":"https://codeload.github.com/serviejs/throwback/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":231590687,"owners_count":18396934,"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":["compose","koa","middleware","popsicle","servie"],"created_at":"2024-12-28T06:15:24.669Z","updated_at":"2024-12-28T06:15:25.417Z","avatar_url":"https://github.com/serviejs.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Throwback\n\n[![NPM version](https://img.shields.io/npm/v/throwback.svg?style=flat)](https://npmjs.org/package/throwback)\n[![NPM downloads](https://img.shields.io/npm/dm/throwback.svg?style=flat)](https://npmjs.org/package/throwback)\n[![Build status](https://img.shields.io/travis/serviejs/throwback.svg?style=flat)](https://travis-ci.org/serviejs/throwback)\n[![Test coverage](https://img.shields.io/coveralls/serviejs/throwback.svg?style=flat)](https://coveralls.io/r/serviejs/throwback?branch=master)\n\n\u003e Simple asynchronous middleware pattern.\n\n## Installation\n\n```\nnpm install throwback --save\n```\n\n## Usage\n\nCompose asynchronous (promise-returning) functions.\n\n```js\nconst { compose } = require(\"throwback\");\n\nconst fn = compose([\n  async function(ctx, next) {\n    console.log(1);\n\n    try {\n      await next();\n    } catch (err) {\n      console.log(\"throwback\", err);\n    }\n\n    console.log(4);\n  },\n  async function(ctx, next) {\n    console.log(2);\n\n    return next();\n  }\n]);\n\n// Callback runs at the end of the stack, before\n// the middleware bubbles back to the beginning.\nfn({}, function(ctx) {\n  console.log(3);\n\n  ctx.status = 404;\n});\n```\n\n**Tip:** In development (`NODE_ENV !== \"production\"`), `compose` will throw errors when you do something unexpected. In production, the faster non-error code paths are used.\n\n### Example\n\nBuild a micro HTTP server!\n\n```js\nconst { createServer } = require(\"http\");\nconst finalhandler = require(\"finalhandler\"); // Example only, not compatible with single `ctx` arg.\nconst { compose } = require(\"throwback\");\n\nconst app = compose([\n  function({ req, res }, next) {\n    res.end(\"Hello world!\");\n  }\n]);\n\ncreateServer(function(req, res) {\n  return app({ req, res }, finalhandler());\n}).listen(3000);\n```\n\n## Use Cases\n\n- HTTP requests (e.g. [`popsicle`](https://github.com/serviejs/popsicle))\n- HTTP servers (e.g. [`servie`](https://github.com/serviejs/servie))\n- Processing pipelines (e.g. [`scrappy`](https://github.com/blakeembrey/node-scrappy))\n\n## Inspiration\n\nBuilt for [`servie`](https://github.com/serviejs) and inspired by [`koa-compose`](https://github.com/koajs/compose).\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserviejs%2Fthrowback","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fserviejs%2Fthrowback","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserviejs%2Fthrowback/lists"}