1# Network Stack Component<a name="EN-US_TOPIC_0000001125689015"></a>
2
3-   [Introduction](#section11660541593)
4-   [Directory Structure](#section1464106163817)
5-   [Available APIs](#section1096322014288)
6-   [Repositories Involved](#section11683135113011)
7
8## Introduction<a name="section11660541593"></a>
9
10The **network stack component** is an adaptation layer framework for developers to develop network protocol stacks such as HTTP, socket and websocket for OpenHarmony applications. At present, it mainly consists of the following two parts:
11
121. NAPI based JS adaptation layer on mini system and small system.
13
14
152. JSI based JS adaptation layer on standard system.
16
17## Directory Structure<a name="section1464106163817"></a>
18
19The source code of the network stack component is stored in **/foundation/communication/netstack**. The directory structure is as follows:
20
21```
22/foundation/communication/netstack
23├── frameworks         # Framework code
24│   ├── js             # JS adaptation
25│       ├── builtin    # JSI based JS adaptation layer on mini system and small system
26│       └── napi       # NAPI based JS adaptation layer on standard system
27├── interfaces         # APIs exposed externally
28│   └── kits           # OpenHarmony SDK API, including Java, JS and native. At present, there is only JS
29│       └── js         # JS API
30├── utils              # Common tools
31│   └── log            # Log tool
32```
33
34## Available APIs<a name="section1096322014288"></a>
35
36```
37export interface FetchResponse {
38  /**
39   * Server status code.
40   * @since 3
41   */
42  code: number;
43
44  /**
45   * Data returned by the success function.
46   * @since 3
47   */
48  data: string | object;
49
50  /**
51   * All headers in the response from the server.
52   * @since 3
53   */
54  headers: Object;
55}
56
57/**
58 * @Syscap SysCap.ACE.UIEngine
59 */
60export default class Fetch {
61  /**
62   * Obtains data through the network.
63   * @param options
64   */
65  static fetch(options: {
66    /**
67     * Resource URL.
68     * @since 3
69     */
70    url: string;
71
72    /**
73     * Request parameter, which can be of the string type or a JSON object.
74     * @since 3
75     */
76    data?: string | object;
77
78    /**
79     * Request header, which accommodates all attributes of the request.
80     * @since 3
81     */
82    header?: Object;
83
84    /**
85     * Request methods available: OPTIONS, GET, HEAD, POST, PUT, DELETE and TRACE. The default value is GET.
86     * @since 3
87     */
88    method?: string;
89
90    /**
91     * 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.
92     * @since 3
93     */
94    responseType?: string;
95
96    /**
97     * Called when the network data is obtained successfully.
98     * @since 3
99     */
100    success?: (data: FetchResponse) => void;
101
102    /**
103     * Called when the network data fails to be obtained.
104     * @since 3
105     */
106    fail?: (data: any, code: number) => void;
107
108    /**
109     * Called when the execution is completed.
110     * @since 3
111     */
112    complete?: () => void;
113  }): void;
114}
115```
116
117## Repositories Involved<a name="section11683135113011"></a>
118
119[ ace_engine_lite ](https://gitee.com/openharmony/ace_engine_lite)
120
121[ third_party_curl ](https://gitee.com/openharmony/third_party_curl)
122
123[ third_party_mbedtls ](https://gitee.com/openharmony/third_party_mbedtls)
124