13 Star 21 Fork 223

OpenHarmony / communication_netstack

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
READEME.md 3.30 KB
一键复制 编辑 原始数据 按行查看 历史
maosiping 提交于 2021-11-17 14:18 . 修改readme

Network Stack Component

Introduction

The 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:

  1. NAPI based JS adaptation layer on mini system and small system.

  2. JSI based JS adaptation layer on standard system.

Directory Structure

The source code of the network stack component is stored in /foundation/communication/netstack. The directory structure is as follows:

/foundation/communication/netstack
├── frameworks         # Framework code
│   ├── js             # JS adaptation
│       ├── builtin    # JSI based JS adaptation layer on mini system and small system
│       └── napi       # NAPI based JS adaptation layer on standard system
├── interfaces         # APIs exposed externally
│   └── kits           # OpenHarmony SDK API, including Java, JS and native. At present, there is only JS
│       └── js         # JS API
├── utils              # Common tools
│   └── log            # Log tool

Available APIs

export interface FetchResponse {
  /**
   * Server status code.
   * @since 3
   */
  code: number;

  /**
   * Data returned by the success function.
   * @since 3
   */
  data: string | object;

  /**
   * All headers in the response from the server.
   * @since 3
   */
  headers: Object;
}

/**
 * @Syscap SysCap.ACE.UIEngine
 */
export default class Fetch {
  /**
   * Obtains data through the network.
   * @param options
   */
  static fetch(options: {
    /**
     * Resource URL.
     * @since 3
     */
    url: string;

    /**
     * Request parameter, which can be of the string type or a JSON object.
     * @since 3
     */
    data?: string | object;

    /**
     * Request header, which accommodates all attributes of the request.
     * @since 3
     */
    header?: Object;

    /**
     * Request methods available: OPTIONS, GET, HEAD, POST, PUT, DELETE and TRACE. The default value is GET.
     * @since 3
     */
    method?: string;

    /**
     * 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.
     * @since 3
     */
    responseType?: string;

    /**
     * Called when the network data is obtained successfully.
     * @since 3
     */
    success?: (data: FetchResponse) => void;

    /**
     * Called when the network data fails to be obtained.
     * @since 3
     */
    fail?: (data: any, code: number) => void;

    /**
     * Called when the execution is completed.
     * @since 3
     */
    complete?: () => void;
  }): void;
}

Repositories Involved

ace_engine_lite

third_party_curl

third_party_mbedtls

1
https://gitee.com/openharmony/communication_netstack.git
git@gitee.com:openharmony/communication_netstack.git
openharmony
communication_netstack
communication_netstack
master

搜索帮助