{"id":13473281,"url":"https://github.com/toajs/toa","last_synced_at":"2025-03-26T17:32:23.811Z","repository":{"id":23754673,"uuid":"27128928","full_name":"toajs/toa","owner":"toajs","description":"A pithy and powerful web framework.","archived":true,"fork":false,"pushed_at":"2021-05-09T08:51:14.000Z","size":984,"stargazers_count":225,"open_issues_count":3,"forks_count":19,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-03-15T08:05:06.656Z","etag":null,"topics":["async-await","generator","javascript","middleware","toa","web-framework"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/toajs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-11-25T14:16:36.000Z","updated_at":"2024-12-31T14:02:34.000Z","dependencies_parsed_at":"2022-08-22T05:50:22.968Z","dependency_job_id":null,"html_url":"https://github.com/toajs/toa","commit_stats":null,"previous_names":[],"tags_count":119,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toajs%2Ftoa","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toajs%2Ftoa/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toajs%2Ftoa/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toajs%2Ftoa/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/toajs","download_url":"https://codeload.github.com/toajs/toa/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245702543,"owners_count":20658632,"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-await","generator","javascript","middleware","toa","web-framework"],"created_at":"2024-07-31T16:01:02.354Z","updated_at":"2025-03-26T17:32:23.430Z","avatar_url":"https://github.com/toajs.png","language":"JavaScript","readme":"# Toa\n\n简洁而强大的 web 框架。\n\n![Toa](https://raw.githubusercontent.com/toajs/toa/master/toa.png)\n\n[![NPM version][npm-image]][npm-url]\n[![Build Status][travis-image]][travis-url]\n[![js-standard-style][js-standard-image]][js-standard-url]\n[![Coverage Status][coveralls-image]][coveralls-url]\n[![Downloads][downloads-image]][downloads-url]\n\n## Thanks to [Koa](https://github.com/koajs/koa) and it's authors\n\n## Demo\n\n```js\nconst ilog = require('ilog')\nconst Toa = require('toa')\n\nconst app = new Toa()\n\napp.use(function () {\n  this.body = 'support sync function middleware!\\n'\n})\n\napp.use(function (next) {\n  this.body += 'support thunk function middleware!\\n'\n  next()\n})\n\napp.use(function * () {\n  this.body += yield Promise.resolve('support generator function middleware!\\n')\n})\n// support in Node.js v8\napp.use(async function () {\n  this.body += await Promise.resolve('support async/await function middleware!\\n')\n})\n\napp.listen(3000, () =\u003e ilog.info('App start at: 3000'))\n```\n\n## TypeScript Demo\n\n```typescript\nimport { Toa } from 'toa'\n\nconst app = new Toa()\n\napp.use(function () {\n  this.body = 'support sync function middleware!\\n'\n})\n\napp.use(function (next) {\n  this.body += 'support thunk function middleware!\\n'\n  next()\n})\n\napp.use(function * () {\n  this.body += yield Promise.resolve('support generator function middleware!\\n')\n})\n\napp.use(async function () {\n  this.body += await Promise.resolve('support async/await function middleware!\\n')\n})\n\napp.listen(3000, () =\u003e console.log('App start at 3000'))\n```\n\n## With HTTP/2\n\n```js\n// Visit: https://127.0.0.1:3000/\nconst http2 = require('http2')\nconst fs = require('fs')\nconst Toa = require('toa')\nconst server = http2.createSecureServer({\n  key: fs.readFileSync('./localhost.key'),\n  cert: fs.readFileSync('./localhost.crt')\n})\n\nconst app = new Toa(server)\napp.use(function () {\n  this.body = 'Hello World!\\n-- toa'\n})\n\napp.listen(3000, () =\u003e console.log('https://127.0.0.1:3000/'))\n```\n\n## Install\n\n```sh\nnpm install toa\n```\n\n## Toa 简介\n\n**Toa** 是 **Koa** 的改进版。\n\n**Toa** 修改自 **Koa**，基本架构原理与 **Koa** 相似，`context`、`request`、`response` 三大基础对象几乎一样。但 **Toa** 是基于 [thunks](https://github.com/thunks/thunks) 组合业务逻辑，来实现异步流程控制和异常处理。\n\n**Toa** 的异步核心是 `thunk` 函数，支持 `node.js v0.10.x`，但在支持 generator 的 node 环境中（io.js, node.js \u003e= v0.11.9）将会有更好地编程体验：**用同步逻辑编写非阻塞的异步程序**。\n\n**Toa** 与 **Koa** 学习成本和编程体验是一致的，两者之间几乎是无缝切换。但 **Toa** 去掉了 **Koa** 的 `级联（Cascading）` 逻辑，强化中间件，强化模块化组件，尽量削弱第三方组件访问应用的能力，使得编写大型应用的结构逻辑更简洁明了，也更安全。\n\n### koa Process\n\n![koa Process](https://raw.githubusercontent.com/toajs/toa/master/doc/process_koa.png)\n\n### Toa Process\n\n![Toa Process](https://raw.githubusercontent.com/toajs/toa/master/doc/process_toa.png)\n\n## 功能模块\n\n与 Koa 一样， Toa 也没有绑定多余的功能，而仅仅提供了一个轻量优雅的函数库，异步控制处理器和强大的扩展能力。\n\n使用者可以根据自己的需求选择独立的功能模块或中间件，或自己实现相关功能模块。以下是 Toajs 提供的基础性的功能模块。它们已能满足大多数的应用需求。\n\n- [toa-pm](https://github.com/toajs/toa-pm) Process events manager for toa.\n- [toa-ejs](https://github.com/toajs/toa-ejs) Ejs render module for toa.\n- [toa-cors](https://github.com/toajs/toa-cors) CORS middleware for Toa.\n- [toa-mejs](https://github.com/toajs/toa-mejs) Mejs render module for toa.\n- [toa-i18n](https://github.com/toajs/toa-i18n) I18n middleware for toa.\n- [toa-body](https://github.com/toajs/toa-body) Request body parser for toa.\n- [toa-token](https://github.com/toajs/toa-token) Token based authentication for toa.\n- [toa-router](https://github.com/toajs/toa-router) A trie router for toa.\n- [toa-static](https://github.com/toajs/toa-static) A static server module for toa.\n- [toa-logging](https://github.com/toajs/toa-logging) HTTP request logger middleware for Toa.\n- [toa-favicon](https://github.com/toajs/toa-favicon) Favicon middleware for toa.\n- [toa-session](https://github.com/toajs/toa-session) Session middleware for toa.\n- [toa-compress](https://github.com/toajs/toa-compress) Compress responses middleware for toa.\n- [toa-ratelimit](https://github.com/toajs/toa-ratelimit) Smart rate limiter module for toa.\n- [toa-cookie-session](https://github.com/toajs/toa-cookie-session) Cookie session middleware for toa.\n\n------\n\n## [Bench](https://github.com/toajs/toa/tree/master/bench)\n\n## API\n\n### [使用手册](https://github.com/toajs/toa/blob/master/doc/guide.md)\n\n### [Application](https://github.com/toajs/toa/blob/master/doc/api/application.md)\n\n### [Context](https://github.com/toajs/toa/blob/master/doc/api/context.md)\n\n### [Request](https://github.com/toajs/toa/blob/master/doc/api/request.md)\n\n### [Response](https://github.com/toajs/toa/blob/master/doc/api/response.md)\n\n## [Change Log](https://github.com/toajs/toa/blob/master/CHANGELOG.md)\n\n[npm-url]: https://npmjs.org/package/toa\n[npm-image]: http://img.shields.io/npm/v/toa.svg\n\n[travis-url]: https://travis-ci.org/toajs/toa\n[travis-image]: http://img.shields.io/travis/toajs/toa.svg\n\n[coveralls-url]: https://coveralls.io/r/toajs/toa\n[coveralls-image]: https://coveralls.io/repos/toajs/toa/badge.svg\n\n[downloads-url]: https://npmjs.org/package/toa\n[downloads-image]: http://img.shields.io/npm/dm/toa.svg?style=flat-square\n\n[js-standard-url]: https://github.com/feross/standard\n[js-standard-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoajs%2Ftoa","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftoajs%2Ftoa","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoajs%2Ftoa/lists"}