1/* 2 * Copyright (c) 2020 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16/** 17 * @devices tv, phone, tablet, wearable 18 */ 19export interface FetchResponse { 20 /** 21 * Server status code. 22 * @devices tv, phone, tablet, wearable 23 * @since 3 24 */ 25 code: number; 26 27 /** 28 * Data returned by the success function. 29 * @devices tv, phone, tablet, wearable 30 * @since 3 31 */ 32 data: string | object; 33 34 /** 35 * All headers in the response from the server. 36 * @devices tv, phone, tablet, wearable 37 * @since 3 38 */ 39 headers: Object; 40} 41 42/** 43 * @devices tv, phone, tablet, wearable 44 */ 45export interface FetchOptions { 46 /** 47 * Resource URL. 48 * @devices tv, phone, tablet, wearable 49 * @since 3 50 */ 51 url: string; 52 53 /** 54 * Request parameter, which can be of the string type or a JSON object. 55 * @devices tv, phone, tablet, wearable 56 * @since 3 57 */ 58 data?: string | object; 59 60 /** 61 * Request header. 62 * @devices tv, phone, tablet, wearable 63 * @since 3 64 */ 65 header?: Object; 66 67 /** 68 * Request methods available: OPTIONS, GET, HEAD, POST, PUT, DELETE and TRACE. 69 * The default value is GET. 70 * @devices tv, phone, tablet, wearable 71 * @since 3 72 */ 73 method?: "OPTIONS" | "GET" | "HEAD" | "POST" | "PUT" | "DELETE" | "TRACE"; 74 75 /** 76 * The return type can be text, or JSON. 77 * By default, the return type is determined based on Content-Type in the header returned by the server. 78 * @devices tv, phone, tablet, wearable 79 * @since 3 80 */ 81 responseType?: string; 82 83 /** 84 * Called when the network data is obtained successfully. 85 * @devices tv, phone, tablet, wearable 86 * @since 3 87 */ 88 success?: (data: FetchResponse) => void; 89 90 /** 91 * Called when the network data fails to be obtained. 92 * @devices tv, phone, tablet, wearable 93 * @since 3 94 */ 95 fail?: (data: any, code: number) => void; 96 97 /** 98 * Called when the execution is completed. 99 * @devices tv, phone, tablet, wearable 100 * @since 3 101 */ 102 complete?: () => void; 103} 104 105/** 106 * @devices tv, phone, tablet, wearable 107 */ 108export default class Fetch { 109 /** 110 * Obtains data through the network. 111 * @param options Options. 112 * @devices tv, phone, tablet, wearable 113 */ 114 static fetch(options: FetchOptions): void; 115} 116