Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/midwayjs/hooks

"Zero" Api / Type Safe / Fullstack Kit / Powerful Backend
https://github.com/midwayjs/hooks

frontend fullstack hooks midway react serverless vite vue

Last synced: about 2 months ago
JSON representation

"Zero" Api / Type Safe / Fullstack Kit / Powerful Backend

Awesome Lists containing this project

README

        

Functional Fullstack Framework










"Zero" Api & Type Safe & Fullstack Kit & Powerful Backend

At Alibaba, 2800+ full-stack applications are developed based on Midway Hooks (2022.01)

English | [简体中文](./README.zh-cn.md)

## ✨ Features

- ☁️ Maximize productivity and developer experience, support fullstack development & API service
- ⚡️ Fullstack kit that supports React/Vue/Svelte... and more frameworks
- 🌈 "Zero" Api data layer, import functions from the backend to call the API directly, without the ajax glue layer
- ⛑️ Type safe, use the identical type definition from frontend to backend, detect errors in advance
- 🌍 Functional programming, using `Hooks` for frontend and backend
- ⚙️ Support for `Webpack / Vite` based projects
- ✈️ Deploy to Server or Serverless
- 🛡 Based on Midway, a powerful Node.js framework that supports enterprise-level application development

## 🔨 Preview

Backend(Midway Hooks)
Frontend(React)

```tsx
// src/api/index.ts
import {
Api,
Get,
Post,
Validate,
Query,
useContext,
} from '@midwayjs/hooks';
import { z } from 'zod';
import db from './database';

export const getArticles = Api(
Get(),
Query<{ page: string; per_page: string }>(),
async () => {
const ctx = useContext();

const articles = await db.articles.find({
page: ctx.query.page,
per_page: ctx.query.per_page,
});

return articles;
}
);

const ArticleSchema = z.object({
title: z.string().min(3).max(16),
content: z.string().min(1),
});

export const createArticle = Api(
Post(),
Validate(ArticleSchema),
async (article: z.infer) => {
const newArticle = await db.articles.create(article);
return {
id: newArticle.id,
};
}
);
```

```ts
// src/pages/articles.tsx
import { getArticles } from '../api';
import { useRequest } from 'ahooks';
import ArticleList from './components/ArticleList';

export default () => {
const { data } = useRequest(() =>
getArticles({
query: {
page: '1',
per_page: '10',
},
})
);

return ;
};

// src/pages/new.tsx
import { createArticle } from '../api';
import Editor from './components/Editor';
import { useState } from 'react';

export default () => {
const [loading, setLoading] = useState(false);

const handleSubmit = async (article) => {
setLoading(true);
const { id } = await createArticle(article);
setLoading(false);
location.href = `/articles/${id}`;
};

return ;
};
```

## 🧩 Templates

Midway Hooks currently provide the following templates:

- Fullstack
- [react](https://github.com/midwayjs/hooks/blob/main/examples/react)
- [vue](https://github.com/midwayjs/hooks/blob/main/examples/vue)
- [prisma](https://github.com/midwayjs/hooks/blob/main/examples/prisma)
- [react-with-upload](https://github.com/midwayjs/hooks/blob/main/examples/react-with-upload)
- Serverless
- [react-faas](https://github.com/midwayjs/hooks/blob/main/examples/react-faas)
- [vue-faas](https://github.com/midwayjs/hooks/blob/main/examples/vue-faas)
- Api Server
- [api](https://github.com/midwayjs/hooks/blob/main/examples/api)
- [api-bundle](https://github.com/midwayjs/hooks/blob/main/examples/api-bundle)

You can create applications quickly with templates:

```bash
npx degit https://github.com/midwayjs/hooks/examples/
```

For example, create a fullstack application with react:

```bash
npx degit https://github.com/midwayjs/hooks/examples/react
```

## Contribute

1. Fork it!
2. Create your feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request :D

We use pnpm to manage the project.

- install dependencies

```bash
$ pnpm install
```

- build

```bash
$ pnpm build
```

- watch

```bash
$ pnpm watch
```

- test

```bash
$ pnpm test
```

## Contributors ✨

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):



Lxxyx
Lxxyx

💻 🖋 🤔 👀 ⚠️ 📖
Gao Yang
Gao Yang

💻 🖋 ⚠️ 📖
狼叔
狼叔

📖
Eward
Eward

💻
Linbudu
Linbudu

📖
rojer
rojer

💻
Thetiso
Thetiso

📖

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!

## About

[Alibaba Open Source](https://opensource.alibaba.com/)

## License

[MIT](LICENSE)