{"id":13496204,"url":"https://github.com/midwayjs/hooks","last_synced_at":"2025-03-28T18:31:44.137Z","repository":{"id":37024059,"uuid":"285555870","full_name":"midwayjs/hooks","owner":"midwayjs","description":"\"Zero\" Api / Type Safe / Fullstack Kit / Powerful Backend","archived":true,"fork":false,"pushed_at":"2023-10-18T17:39:09.000Z","size":5455,"stargazers_count":689,"open_issues_count":12,"forks_count":63,"subscribers_count":16,"default_branch":"main","last_synced_at":"2024-10-20T04:48:05.452Z","etag":null,"topics":["frontend","fullstack","hooks","midway","react","serverless","vite","vue"],"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/midwayjs.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}},"created_at":"2020-08-06T11:42:00.000Z","updated_at":"2024-10-17T06:29:41.000Z","dependencies_parsed_at":"2024-01-16T10:08:55.443Z","dependency_job_id":null,"html_url":"https://github.com/midwayjs/hooks","commit_stats":{"total_commits":977,"total_committers":16,"mean_commits":61.0625,"dds":"0.22722620266120774","last_synced_commit":"07595bfc144aa7b4ca1719f60454a4b947ffe88c"},"previous_names":[],"tags_count":352,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/midwayjs%2Fhooks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/midwayjs%2Fhooks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/midwayjs%2Fhooks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/midwayjs%2Fhooks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/midwayjs","download_url":"https://codeload.github.com/midwayjs/hooks/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222189597,"owners_count":16946004,"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":["frontend","fullstack","hooks","midway","react","serverless","vite","vue"],"created_at":"2024-07-31T19:01:43.761Z","updated_at":"2024-10-31T11:31:00.080Z","avatar_url":"https://github.com/midwayjs.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003eFunctional Fullstack Framework\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://www.npmjs.com/package/@midwayjs/hooks\"\u003e\n    \u003cimg src=\"https://img.shields.io/npm/v/@midwayjs/hooks/latest?style=for-the-badge\"\u003e\n  \u003c/a\u003e\n  \u003cimg src=\"https://img.shields.io/github/workflow/status/midwayjs/hooks/Node.js%20CI/master?style=for-the-badge\"\u003e\n  \u003ca href=\"https://codecov.io/gh/midwayjs/hooks\"\u003e\n    \u003cimg src=\"https://img.shields.io/codecov/c/github/midwayjs/hooks?style=for-the-badge\"\u003e\n  \u003c/a\u003e\n  \u003cimg src=\"https://img.shields.io/npm/l/@midwayjs/hooks?style=for-the-badge\"\u003e\n\u003c/p\u003e\n\n\u003ch5 align=\"center\"\u003e\"Zero\" Api \u0026 Type Safe \u0026 Fullstack Kit \u0026 Powerful Backend\u003c/h5\u003e\n\u003ch5 align=\"center\"\u003eAt Alibaba, 2800+ full-stack applications are developed based on Midway Hooks (2022.01)\u003c/h5\u003e\n\nEnglish | [简体中文](./README.zh-cn.md)\n\n## ✨ Features\n\n- ☁️ Maximize productivity and developer experience, support fullstack development \u0026 API service\n- ⚡️ Fullstack kit that supports React/Vue/Svelte... and more frameworks\n- 🌈 \"Zero\" Api data layer, import functions from the backend to call the API directly, without the ajax glue layer\n- ⛑️ Type safe, use the identical type definition from frontend to backend, detect errors in advance\n- 🌍 Functional programming, using `Hooks` for frontend and backend\n- ⚙️ Support for `Webpack / Vite` based projects\n- ✈️ Deploy to Server or Serverless\n- 🛡 Based on Midway, a powerful Node.js framework that supports enterprise-level application development\n\n## 🔨 Preview\n\n\u003ctable\u003e\n\u003ctr\u003e\n\u003cth style=\"text-align: center;\"\u003e Backend(Midway Hooks) \u003c/th\u003e\n\u003cth style=\"text-align: center;\"\u003e Frontend(React) \u003c/th\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\n\u003csub\u003e\n\n\u003c!-- prettier-ignore --\u003e\n```tsx\n// src/api/index.ts\nimport {\n  Api,\n  Get,\n  Post,\n  Validate,\n  Query,\n  useContext,\n} from '@midwayjs/hooks';\nimport { z } from 'zod';\nimport db from './database';\n\nexport const getArticles = Api(\n  Get(),\n  Query\u003c{ page: string; per_page: string }\u003e(),\n  async () =\u003e {\n    const ctx = useContext();\n\n    const articles = await db.articles.find({\n      page: ctx.query.page,\n      per_page: ctx.query.per_page,\n    });\n\n    return articles;\n  }\n);\n\nconst ArticleSchema = z.object({\n  title: z.string().min(3).max(16),\n  content: z.string().min(1),\n});\n\nexport const createArticle = Api(\n  Post(),\n  Validate(ArticleSchema),\n  async (article: z.infer\u003ctypeof ArticleSchema\u003e) =\u003e {\n    const newArticle = await db.articles.create(article);\n    return {\n      id: newArticle.id,\n    };\n  }\n);\n```\n\n\u003c/sub\u003e\n\u003c/td\u003e\n\u003ctd\u003e\n\n\u003csub\u003e\n\n```ts\n// src/pages/articles.tsx\nimport { getArticles } from '../api';\nimport { useRequest } from 'ahooks';\nimport ArticleList from './components/ArticleList';\n\nexport default () =\u003e {\n  const { data } = useRequest(() =\u003e\n    getArticles({\n      query: {\n        page: '1',\n        per_page: '10',\n      },\n    })\n  );\n\n  return \u003cArticleList articles={data} /\u003e;\n};\n\n// src/pages/new.tsx\nimport { createArticle } from '../api';\nimport Editor from './components/Editor';\nimport { useState } from 'react';\n\nexport default () =\u003e {\n  const [loading, setLoading] = useState(false);\n\n  const handleSubmit = async (article) =\u003e {\n    setLoading(true);\n    const { id } = await createArticle(article);\n    setLoading(false);\n    location.href = `/articles/${id}`;\n  };\n\n  return \u003cEditor loading={loading} onSubmit={handleSubmit} /\u003e;\n};\n```\n\n\u003c/sub\u003e\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\n## 🧩 Templates\n\nMidway Hooks currently provide the following templates:\n\n- Fullstack\n  - [react](https://github.com/midwayjs/hooks/blob/main/examples/react)\n  - [vue](https://github.com/midwayjs/hooks/blob/main/examples/vue)\n  - [prisma](https://github.com/midwayjs/hooks/blob/main/examples/prisma)\n  - [react-with-upload](https://github.com/midwayjs/hooks/blob/main/examples/react-with-upload)\n- Serverless\n  - [react-faas](https://github.com/midwayjs/hooks/blob/main/examples/react-faas)\n  - [vue-faas](https://github.com/midwayjs/hooks/blob/main/examples/vue-faas)\n- Api Server\n  - [api](https://github.com/midwayjs/hooks/blob/main/examples/api)\n  - [api-bundle](https://github.com/midwayjs/hooks/blob/main/examples/api-bundle)\n\nYou can create applications quickly with templates:\n\n```bash\nnpx degit https://github.com/midwayjs/hooks/examples/\u003cname\u003e\n```\n\nFor example, create a fullstack application with react:\n\n```bash\nnpx degit https://github.com/midwayjs/hooks/examples/react\n```\n\n## Contribute\n\n1. Fork it!\n2. Create your feature branch: `git checkout -b my-new-feature`\n3. Commit your changes: `git commit -am 'Add some feature'`\n4. Push to the branch: `git push origin my-new-feature`\n5. Submit a pull request :D\n\nWe use pnpm to manage the project.\n\n- install dependencies\n\n```bash\n$ pnpm install\n```\n\n- build\n\n```bash\n$ pnpm build\n```\n\n- watch\n\n```bash\n$ pnpm watch\n```\n\n- test\n\n```bash\n$ pnpm test\n```\n\n## Contributors ✨\n\nThanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --\u003e\n\u003c!-- prettier-ignore-start --\u003e\n\u003c!-- markdownlint-disable --\u003e\n\u003ctable\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd align=\"center\"\u003e\u003ca href=\"https://blog.lxxyx.cn/\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/13161470?v=4?s=100\" width=\"100px;\" alt=\"Lxxyx\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eLxxyx\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/midwayjs/hooks/commits?author=Lxxyx\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"#content-Lxxyx\" title=\"Content\"\u003e🖋\u003c/a\u003e \u003ca href=\"#ideas-Lxxyx\" title=\"Ideas, Planning, \u0026 Feedback\"\u003e🤔\u003c/a\u003e \u003ca href=\"https://github.com/midwayjs/hooks/pulls?q=is%3Apr+reviewed-by%3ALxxyx\" title=\"Reviewed Pull Requests\"\u003e👀\u003c/a\u003e \u003ca href=\"https://github.com/midwayjs/hooks/commits?author=Lxxyx\" title=\"Tests\"\u003e⚠️\u003c/a\u003e \u003ca href=\"https://github.com/midwayjs/hooks/commits?author=Lxxyx\" title=\"Documentation\"\u003e📖\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\"\u003e\u003ca href=\"https://iam.gy/\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/14832743?v=4?s=100\" width=\"100px;\" alt=\"Gao Yang\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eGao Yang\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/midwayjs/hooks/commits?author=echosoar\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"#content-echosoar\" title=\"Content\"\u003e🖋\u003c/a\u003e \u003ca href=\"https://github.com/midwayjs/hooks/commits?author=echosoar\" title=\"Tests\"\u003e⚠️\u003c/a\u003e \u003ca href=\"https://github.com/midwayjs/hooks/commits?author=echosoar\" title=\"Documentation\"\u003e📖\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\"\u003e\u003ca href=\"http://i5ting.com/\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/3118295?v=4?s=100\" width=\"100px;\" alt=\"狼叔\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003e狼叔\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/midwayjs/hooks/commits?author=i5ting\" title=\"Documentation\"\u003e📖\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\"\u003e\u003ca href=\"https://www.yuque.com/eward/blog\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/452899?v=4?s=100\" width=\"100px;\" alt=\"Eward\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eEward\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/midwayjs/hooks/commits?author=shepherdwind\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\"\u003e\u003ca href=\"https://linbudu.top/\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/48507806?v=4?s=100\" width=\"100px;\" alt=\"Linbudu\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eLinbudu\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/midwayjs/hooks/commits?author=linbudu599\" title=\"Documentation\"\u003e📖\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/rojer95\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/20662049?v=4?s=100\" width=\"100px;\" alt=\"rojer\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003erojer\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/midwayjs/hooks/commits?author=rojer95\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/Thetiso\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/8968567?v=4?s=100\" width=\"100px;\" alt=\"Thetiso\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eThetiso\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/midwayjs/hooks/commits?author=Thetiso\" title=\"Documentation\"\u003e📖\u003c/a\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n\u003c!-- markdownlint-restore --\u003e\n\u003c!-- prettier-ignore-end --\u003e\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n\nThis project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!\n\n## About\n\n[Alibaba Open Source](https://opensource.alibaba.com/)\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmidwayjs%2Fhooks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmidwayjs%2Fhooks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmidwayjs%2Fhooks/lists"}