🚀 Develop & Ship
Midway Hooks 是下一代的云端一体应用研发方案。通过 Serverless + Hooks + 一体化 Api 调用的特性,开发者在研发流程中仅需关注业务逻辑,即可高效完成应用的交付。
✨ 特性
- ☁️ 全栈,在 src 目录中开发前后端代码
- 🌈 极其简单的后端 Api 开发与调用方式
- 🌍 使用 “React Hooks” 开发后端
- 📦 跨前端框架. 支持 React / Vue3 / ICE.js
- ⚙️ 基于 Midway, 提供 Web 及 Serverless 场景下的完整支持.
- 🛡 完善的 TypeScript 支持
🌰 Demo
从后端导入代码并调用
backend api
export async function get() {return 'Hello Midway Hooks'}export async function post(name: string) {return 'Hello ' + name}
frontend
import { get, post } from './apis/lambda'/*** @method GET* @url /api/get*/get().then((message) => {// Display: Hello Midway Hooksconsole.log(message)})/*** @method POST* @url /api/post* @body { args: ['github'] }*/post('github').then((message) => {// Display: Hello githubconsole.log(message)})
Hooks
backend api
import { useContext } from '@midwayjs/hooks'export async function getPath() {const ctx = useContext()return ctx.path}
frontend
import { getPath } from './apis/lambda'/*** @method GET* @url /api/getPath*/getPath().then((path) => {// Display: /api/getPathconsole.log(path)})
🚀 快速开始
请先安装 faas-cli.
npm i @midwayjs/faas-cli -g
创建
React
f create --template-package=@midwayjs-examples/midway-hooks-react
Vue
$ f create --template-package=@midwayjs-examples/midway-hooks-vue3
ICE.js
$ npm init ice ice-app --template @icedesign/scaffold-midway-faas
运行
npm start
部署
f deploy
📚 更多
请查看完整的文档:https://www.yuque.com/midwayjs/faas/hooks

