apiRequestByHighway(params: Object)

Requires:
MiniKit≥2.3.6@ray-js/ray≥0.5.9
Platforms:
iOSAndroid
import { apiRequestByHighway } from '@ray-js/ray';

// Promise usage
try {
  const res = await apiRequestByHighway({ ...params });
  console.log(res);
} catch (err) {
  console.log(err.errorMsg);
}

Description

Initiate a highway request

Parameters

PropertyTypeRequiredDefaultDescriptionMiniKit Since
apistringYes-API name-
No-Highway API request parameters; field structure is defined by the Highway interface for the specified api-
method"OPTIONS" | "GET" | "HEAD" | "POST" | "PUT" | "DELETE" | "TRACE" | "CONNECT"No'GET'method request method-
requestIdstringNo-requestId request ID, not exposed to business codev3.27.0
No-cache cache configurationv3.27.0
complete() => voidNo-Completion callback (executed on both success and failure)-
success(params: Object) => voidNo-Callback on successful API call-
fail(params: Object) => voidNo-Failure callback-
success callback parameters
PropertyTypeDescriptionMiniKit Since
Raw API response datav3.2.0
fail callback parameters
PropertyTypeDescription
errorMsgstringError message
errorCodestring | numberError code
Error extension

Return Value

None

Valid Values

method
ValueDescriptionMiniKit Since
GETHTTP GET requestv3.4.0
POSTHTTP POST requestv3.4.0
PUTHTTP PUT requestv3.4.0
DELETEHTTP DELETE requestv3.4.0
ApiRequestCacheBean.policy
ValueDescriptionMiniKit Since
NETWORK_ONLYOnly send a network request, do not use cachev4.24.0
CACHE_ELSE_NETWORKUse cache first; if not present, send a network requestv4.24.0
CACHE_THEN_NETWORKPrefer cache while also sending a network request; the network result will be delivered via eventsv4.24.0

Examples

import { apiRequestByHighway } from '@ray-js/ray'

// Highway RESTful request: api is a "/v1.0/..." url, method is GET/POST,
// data depends on the specific highway api. (Real usage from @ray-js/ray miniapps.)
apiRequestByHighway({
  api: "/v1.0/m/tc/album/pic/batch/download/url",
  method: "POST",
  data: {},
  success: data => {
    console.log(data);
  },
  fail: error => {
    console.error(error);
  },
});