Skip to main content
Version: v3

Quick Start

Tips

If you haven't learned about alova yet, it is recommended that you read introduce alova first.

And we provide a Tutorial in 5 minutes video to help you learn alova quickly.

Installation

npm install alova --save

Create an alova instance

In alova, you need to initiate a request through an alova instance. Let's create one first. When creating an alova instance, you need to specify a request adapter. Here we recommend using the alova/fetch request adapter, which is a wrapper based on the fetch API and is very concise.

import { createAlova } from 'alova';
import adapterFetch from 'alova/fetch';

const alovaInstance = createAlova({
requestAdapter: adapterFetch(),
responded: response => response.json()
});

GET request

Send a request through alovaInstance.Get. Since the adapterFetch request adapter is used, a Response instance will be received. This is very simple.

const response = await alovaInstance.Get('https://alovajs.dev/user/profile');

In an asynchronous function, you can also use await alovaInstance.Get to wait for the response.

POST request

Submit data through alovaInstance.Post. This is also very simple.

const response = alovaInstance.Post('https://alovajs.dev/posts', {
title: 'foo',
body: 'bar',
userId: 1
});

What to do next?

In fact, this is just a simple request example. You will learn more functions in the next chapter. Let's start learning.