Skip to content

Commit 8f79296

Browse files
committed
Merge branch 'feature/[email protected]'
2 parents e924c06 + bf1934f commit 8f79296

File tree

41 files changed

+3111
-1035
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+3111
-1035
lines changed

docs/resource/01-request-adapter/05-uniapp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const alovaInst = createAlova({
5555

5656
### Request
5757

58-
The usage method of the request is exactly the same as that used in the web environment. Already fully compatible with `uni.request`, you can specify [all configuration items] supported by `uni.request` in _config_ of method instance creation (https://uniapp.dcloud.net.cn/api/request/ request.html)
58+
The usage method of the request is exactly the same as that used in the web environment. Already fully compatible with `uni.request`, you can specify [all configuration items](https://uniapp.dcloud.net.cn/api/request/request.html) supported by `uni.request` in _config_ of method instance creation.
5959

6060
```html
6161
<template>

docs/resource/02-storage-adapter/01-psc.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ We implemented two adapters that can be used in Node.js and Electron.
88

99
:::info Tips
1010

11-
Only supports Alova 3.0 and above.
11+
Only alova 3.0+ is supported.
1212

1313
:::
1414

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
title: File Storage Adapter
3+
---
4+
5+
Store data through files, use atomic file operations, and support server clusters.
6+
7+
:::info Tips
8+
9+
Only alova 3.0+ is supported.
10+
11+
:::
12+
13+
## Installation
14+
15+
```bash
16+
# npm
17+
npm install alova @alova/storage-file --save
18+
# yarn
19+
yarn add alova @alova/storage-file
20+
# npm
21+
pnpm install alova @alova/storage-file
22+
```
23+
24+
## Usage
25+
26+
Create `FileStorageAdapter` and specify the file storage directory. If the directory does not exist, it will be created automatically.
27+
28+
```javascript
29+
const { createAlova } = require('alova');
30+
const FileStorageAdapter = require('@alova/storage-file');
31+
32+
const dir = '~/alova/storage';
33+
const fileAdapter = new FileStorageAdapter({ directory: dir });
34+
const alovaInstance = createAlova({
35+
// ...
36+
l2Cache: fileAdapter
37+
});
38+
```
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
---
2+
title: Redis Storage Adapter
3+
---
4+
5+
Store data through redis and support distributed clusters. Use [ioredis](https://www.npmjs.com/package/ioredis) to implement it.
6+
7+
:::info Tips
8+
9+
Only alova 3.0+ is supported.
10+
11+
:::
12+
13+
## Installation
14+
15+
```bash
16+
# npm
17+
npm install alova @alova/storage-redis --save
18+
# yarn
19+
yarn add alova @alova/storage-redis
20+
# npm
21+
pnpm install alova @alova/storage-redis
22+
```
23+
24+
## Usage
25+
26+
### Basic usage
27+
28+
Create `RedisStorageAdapter` and specify the redis server connection information.
29+
30+
```javascript
31+
const { createAlova } = require('alova');
32+
const RedisStorageAdapter = require('@alova/storage-redis');
33+
34+
const redisAdapter = new RedisStorageAdapter({
35+
host: 'localhost',
36+
port: '6379',
37+
username: 'default',
38+
password: 'my-top-secret',
39+
db: 0
40+
});
41+
const alovaInstance = createAlova({
42+
// ...
43+
l2Cache: redisAdapter
44+
});
45+
```
46+
47+
### Set the storage key prefix
48+
49+
By default, the storage key prefix is ​​`alova:`, which can be set via `keyPrefix`.
50+
51+
```javascript
52+
const redisAdapter = new RedisStorageAdapter({
53+
host: 'localhost',
54+
port: '6379',
55+
username: 'default',
56+
password: 'my-top-secret',
57+
db: 0,
58+
59+
// highlight-start
60+
keyPrefix: 'my-app:'
61+
// highlight-end
62+
});
63+
```
64+
65+
### Use an external redis instance
66+
67+
If you already have an `ioredis` instance in your project and want to use it for operations, you can set it through `client`.
68+
69+
```javascript
70+
const redisAdapter = new RedisStorageAdapter({
71+
client: originalRedisClient
72+
});
73+
```

docs/tutorial/02-getting-started/01-introduce.md

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,20 @@ import TabItem from '@theme/TabItem';
1414

1515
## What is alova?
1616

17-
Alova (pronounced `/əˈləʊva/`<AudioPlayer src={tts} />) is a next-generation request library that radically simplifies your API integration workflow, reducing what used to take 7 complex steps down to just 1 - simply select your API and go.
17+
alova​​ (pronounced /əˈləʊva/<AudioPlayer src={tts} />) is a request toolkit design for API integrating with ​​ultimate efficiency. it seamlessly works with your favorite HTTP clients and UI frameworks, accelerating business logic development for both client and server apps, while enabling interactive API information within your code. bridging the backend collaboration gap like a wormhole.
1818

19-
Unlike libraries such as `@tanstack/react-request`, `swrjs`, and `useRequest` from `ahooks`, alova revolutionizes your development experience by wrapping `fetch/XMLHttpRequest/axios` into request adapters and providing intelligent request strategies for even the most complex scenarios.
20-
21-
Want to dive into the origin story? Check out [Why we created alova](/about/faqs). For a deep dive into how we're different, explore our comprehensive [comparison with other request libraries](/about/comparison).
19+
Learn about our story in [why built alova](/about/faqs), and explore how we differ in our detailed [comparison with other request libraries](/about/comparison).
2220

2321
## Features
2422

25-
- Incredibly simple to use with a minimal learning curve.
26-
- More modern OpenAPI solution - say goodbye to tedious intermediate API documentation.
27-
- Compatible with client-side technologies and request libraries: `react/vue/svelte/solid/next/nuxt/sveltkit/solid-start/uniapp/taro/...` + `fetch/XMLHttpRequest/axios/...`
28-
- Compatible with server-side technologies and request libraries: `nodejs/deno/bun/...` + `fetch/XMLHttpRequest/axios/...`
29-
- 15+ high-performance request strategies to handle complex request scenarios, helping you develop more efficient applications faster.
23+
- ​​Easy to use, [watching video](/video-tutorial) to get started in 5 mins.
24+
- ​​Full compatibility​​ with your favorite technology stack.
25+
- ​​20+ high-performance business modules​​ for building faster apps.
26+
- ​​Advanced OpenAPI solution​​ for efficient APIs information interaction within your code.
27+
- Request sharing and response cache to improve app performance.
28+
- Type safety.
29+
30+
<SupportList showStatus></SupportList>
3031

3132
## Live Demo
3233

@@ -414,12 +415,6 @@ With the various features of alova, you can also build a Client-Server interacti
414415

415416
> To learn how to build a CS Interaction Layer, refer to [Building the Client-Server Interaction Layer](/tutorial/project/best-practice/csil)
416417
417-
## Run in any JS environment
418-
419-
alova is very flexible, you can use it with various request tools across any JavaScript environment (grayed-out options will be gradually supported in the future).
420-
421-
<SupportList showStatus></SupportList>
422-
423418
## Migration Guide
424419

425420
- [Migration from v2 to v3](/tutorial/project/migration/v2-to-v3)

docs/tutorial/02-getting-started/03-basic/07-combine-framework.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const alovaInstance = createAlova({
3838

3939
</TabItem>
4040

41-
<TabItem value="2" label="react">
41+
<TabItem value="2" label="react/next">
4242

4343
```js
4444
import { createAlova } from 'alova';
@@ -52,6 +52,25 @@ export const alovaInstance = createAlova({
5252
});
5353
```
5454

55+
</TabItem>
56+
<TabItem value="6" label="nuxt">
57+
58+
```js
59+
import { createAlova } from 'alova';
60+
import NuxtHook from 'alova/nuxt';
61+
62+
export const alovaInstance = createAlova({
63+
// ...
64+
// highlight-start
65+
statesHook: NuxtHook({
66+
nuxtApp: useNuxtApp
67+
})
68+
// highlight-end
69+
});
70+
```
71+
72+
For more usage about NuxtHook,please refer to [SSR#nuxt](/tutorial/advanced/in-depth/ssr#nuxt3)
73+
5574
</TabItem>
5675
<TabItem value="3" label="svelte">
5776

docs/tutorial/02-getting-started/03-basic/08-server.md

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,46 +23,49 @@ On the server, we also have different request scenarios, such as request retries
2323
The following is an example that combines `retry` and `sendCaptcha`, which implements sending verification codes by retrying after failure:
2424

2525
```js
26-
const { retry, sendCaptcha } = require('alova/server');
26+
const { retry, createCaptchaProvider } = require('alova/server');
2727

28-
const email = '[email protected]';
29-
// Create a method instance for sending verification codes
30-
const captchaMethod = alovaInstance.Post('/api/captcha', {
31-
email,
32-
content: 'captcha content'
28+
const { sendCaptcha } = createCaptchaProvider({
29+
store: redisAdapter
3330
});
3431

35-
// Use retry hook to wrap captchaMethod
36-
const retringMethod = retry(captchaMethod, {
32+
// step1: create a method instance to send code.
33+
const createCaptchaMethod = (code, key) = > alovaInstance.Post('/api/captcha', {
34+
code,
35+
email: key,
36+
});
37+
38+
// step2: wrap `createCaptchaMethod` with sendCaptcha hook.
39+
const captchaMethod = sendCaptcha(createCaptchaMethod, {
40+
41+
});
42+
43+
// step3: wrap `captchaMethod` with retry hook, and get the response result through `await`
44+
const result = await retry(captchaMethod, {
3745
retry: 3,
3846
backoff: {
3947
delay: 2000
4048
}
4149
});
42-
// Use sendCaptcha hook to wrap retringMethod, and send the request and get the response result through await
43-
const result = await sendCaptcha(retringMethod, {
44-
key: email
45-
});
4650
```
4751

4852
You can also use multiple `server hooks` to wrap method instances directly.
4953

50-
```ts
51-
const result = await sendCaptcha(
52-
retry(
53-
alovaInstance.Post('/api/captcha', {
54-
email,
55-
content: 'captcha content'
56-
}),
57-
{
58-
retry: 3,
59-
backoff: {
60-
delay: 2000
61-
}
62-
}
54+
```javascript
55+
const result = await retry(
56+
sendCaptcha(
57+
(code, key) =>
58+
alovaInstance.Post('/api/captcha', {
59+
email,
60+
content: 'captcha content'
61+
}),
62+
{ key: '[email protected]' }
6363
),
6464
{
65-
key: email
65+
retry: 3,
66+
backoff: {
67+
delay: 2000
68+
}
6669
}
6770
);
6871
```

0 commit comments

Comments
 (0)