11e934351Sopenharmony_ci/* 21e934351Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 31e934351Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 41e934351Sopenharmony_ci * you may not use this file except in compliance with the License. 51e934351Sopenharmony_ci * You may obtain a copy of the License at 61e934351Sopenharmony_ci * 71e934351Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 81e934351Sopenharmony_ci * 91e934351Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 101e934351Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 111e934351Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 121e934351Sopenharmony_ci * See the License for the specific language governing permissions and 131e934351Sopenharmony_ci * limitations under the License. 141e934351Sopenharmony_ci */ 151e934351Sopenharmony_ci 161e934351Sopenharmony_ci/** 171e934351Sopenharmony_ci * @since 3 181e934351Sopenharmony_ci * @syscap SystemCapability.Communication.NetStack 191e934351Sopenharmony_ci */ 201e934351Sopenharmony_ciexport interface FetchResponse { 211e934351Sopenharmony_ci /** 221e934351Sopenharmony_ci * Server status code. 231e934351Sopenharmony_ci * @since 3 241e934351Sopenharmony_ci */ 251e934351Sopenharmony_ci code: number; 261e934351Sopenharmony_ci 271e934351Sopenharmony_ci /** 281e934351Sopenharmony_ci * Data returned by the success function. 291e934351Sopenharmony_ci * @since 3 301e934351Sopenharmony_ci */ 311e934351Sopenharmony_ci data: string | object; 321e934351Sopenharmony_ci 331e934351Sopenharmony_ci /** 341e934351Sopenharmony_ci * All headers in the response from the server. 351e934351Sopenharmony_ci * @since 3 361e934351Sopenharmony_ci */ 371e934351Sopenharmony_ci headers: Object; 381e934351Sopenharmony_ci} 391e934351Sopenharmony_ci 401e934351Sopenharmony_ci/** 411e934351Sopenharmony_ci * @since 3 421e934351Sopenharmony_ci * @syscap SystemCapability.Communication.NetStack 431e934351Sopenharmony_ci */ 441e934351Sopenharmony_ciexport default class Fetch { 451e934351Sopenharmony_ci /** 461e934351Sopenharmony_ci * Obtains data through the network. 471e934351Sopenharmony_ci * @param options 481e934351Sopenharmony_ci */ 491e934351Sopenharmony_ci static fetch(options: { 501e934351Sopenharmony_ci /** 511e934351Sopenharmony_ci * Resource URL. 521e934351Sopenharmony_ci * @since 3 531e934351Sopenharmony_ci */ 541e934351Sopenharmony_ci url: string; 551e934351Sopenharmony_ci 561e934351Sopenharmony_ci /** 571e934351Sopenharmony_ci * Request parameter, which can be of the string type or a JSON object. 581e934351Sopenharmony_ci * @since 3 591e934351Sopenharmony_ci */ 601e934351Sopenharmony_ci data?: string | object; 611e934351Sopenharmony_ci 621e934351Sopenharmony_ci /** 631e934351Sopenharmony_ci * Request header, which accommodates all attributes of the request. 641e934351Sopenharmony_ci * @since 3 651e934351Sopenharmony_ci */ 661e934351Sopenharmony_ci header?: Object; 671e934351Sopenharmony_ci 681e934351Sopenharmony_ci /** 691e934351Sopenharmony_ci * Request methods available: OPTIONS, GET, HEAD, POST, PUT, DELETE and TRACE. The default value is GET. 701e934351Sopenharmony_ci * @since 3 711e934351Sopenharmony_ci */ 721e934351Sopenharmony_ci method?: string; 731e934351Sopenharmony_ci 741e934351Sopenharmony_ci /** 751e934351Sopenharmony_ci * The return type can be text, or JSON. By default, the return type is determined based on Content-Type in the header returned by the server. 761e934351Sopenharmony_ci * @since 3 771e934351Sopenharmony_ci */ 781e934351Sopenharmony_ci responseType?: string; 791e934351Sopenharmony_ci 801e934351Sopenharmony_ci /** 811e934351Sopenharmony_ci * Called when the network data is obtained successfully. 821e934351Sopenharmony_ci * @since 3 831e934351Sopenharmony_ci */ 841e934351Sopenharmony_ci success?: (data: FetchResponse) => void; 851e934351Sopenharmony_ci 861e934351Sopenharmony_ci /** 871e934351Sopenharmony_ci * Called when the network data fails to be obtained. 881e934351Sopenharmony_ci * @since 3 891e934351Sopenharmony_ci */ 901e934351Sopenharmony_ci fail?: (data: any, code: number) => void; 911e934351Sopenharmony_ci 921e934351Sopenharmony_ci /** 931e934351Sopenharmony_ci * Called when the execution is completed. 941e934351Sopenharmony_ci * @since 3 951e934351Sopenharmony_ci */ 961e934351Sopenharmony_ci complete?: () => void; 971e934351Sopenharmony_ci }): void; 981e934351Sopenharmony_ci} 99