Skip to main content

Detailed request method

The alova instance object provides abstract objects of seven request methods, including GET, POST, PUT, DELETE, HEAD, OPTIONS, and PATCH. For ease of use, alova uses the same parameter structure as axios.

instance creation functionparameters
GETalovaInstance.Get(url[, config])
POSTalovaInstance.Post(url[, data[, config]])
PUTalova.Put(url[, data[, config]])
DELETEalova.Delete(url[, data[, config]])
HEADalova.Head(url[, config])
OPTIONSalova.Options(url[, config])
PATCHalova.Patch(url[, data[, config]])

Parameter Description:

  • url is the request path, it will be spliced with baseURL in createAlova to form a complete url for request;
  • data is the request body data object;
  • config is the request configuration object, which contains configurations such as request headers, params parameters, and request behavior parameters;

config parameter description

General configuration items

The config object has a total of 10 common configuration items.

NameDescription
namemethod instance name, it is generally used for matching method instance
paramsSet url parameters, see Request Method Instance for details
headersSet request headers, see Request Method Instance for details
transformDataSet the response data transformation function, see Transform Response Data for details
localCacheSet request-level cache mode, see Cache Mode for details
timeoutSet request-level timeout
enableDownloadEnable download progress information, see Download/Upload Progress for details
enableUploadEnable upload progress information, see Download/Upload Progress for details
hitSourceCache auto-invalidation setting, see Auto-invalidate cache for details
shareRequestShare request, see Share Request for details

Adapter configuration items

It varies according to different requestAdapter configurations. For example, the GlobalFetch adapter will retain all the configuration items of config in fetch(url, config). The specific supported configuration items can be viewed in different request adapter documents.

instance method

NameDescription
sendSend a request directly, see Send Request Directly for details
setNameDynamically set the name of the method instance, which is generally used when the name needs to be set later, such as setting the name according to the response data after the response.
abortabort the request sent by the current method instance, it can abort request sent by use hook and directly call send

setName Example

// Use the data id as the name of the current method after the request is successful
onSuccess(event => {
event.method.setName(event.data.id);
});