HarmonyOS provides multiple network request frameworks, including RCP (Remote Communication Kit), HTTP/HTTPS in Network Kit……

Read the original article:HarmonyOS provides multiple network request frameworks, including RCP (Remote Communication Kit), HTTP/HTTPS in Network Kit, and third-party libr

Context

HarmonyOS provides multiple network request frameworks, including RCP (Remote Communication Kit), Network Kit HTTP/HTTPS, and third-party libraries such as Axios. Developers often wonder how to choose the appropriate framework for their applications.

Description

  • Remote Communication Kit (RCP): Provides both HTTP request capabilities and a high-performance URPC (Unified Remote Procedure Call) communication library.
  • Network Kit: The system-provided network library in HarmonyOS that supports HTTP/HTTPS, WebSocket, Socket connections, and network management.
  • Axios: A third-party Promise-based HTTP request library widely used in web and Node.js environments.

Solution / Approach

Remote Communication Kit (RCP)

  • Functionality: Provides HTTP request support and URPC for remote procedure calls.
  • Advantages:
    • Supports cross-device and cross-service remote calls, ideal for distributed applications.
    • Optimized for high-frequency remote calls.
    • Provides secure transmission to ensure data security.
  • Disadvantages: May be overly complex for simple HTTP requests.

  • Applicable Scenarios: Best for distributed scenarios requiring multi-device/service remote invocation.

Network Kit

  • Functionality: Supports HTTP requests, WebSocket, Socket connections, network connection management, and MDNS management.
  • Advantages:
    • Supports standard HTTP methods (GET/POST/PUT, etc.).
    • Deeply integrated with HarmonyOS for network state management and connection pool optimization.
    • Provides HTTPS support for secure data transfer.
  • Disadvantages: Basic functionality; more complex needs may require additional features.

  • Applicable Scenarios: Ideal for standard web service requests, form submission, file upload/download.

Axios

  • Functionality: Provides HTTP requests with Promise API, interceptors, request/response transformation, and automatic JSON conversion.
  • Advantages:
    • Easy asynchronous handling with Promise API.
    • Supports interceptors, request cancellation, and automatic data conversion.
    • Widely used in frontend development with strong community support.
  • Disadvantages:

    • As a third-party library, requires extra configuration in HarmonyOS.
    • May have compatibility issues.
  • Applicable Scenarios: Suitable for complex HTTP request handling, such as interceptors and automatic transformations, or when sharing the same code across Web, Node.js, and HarmonyOS.

Key Takeaways

  • Cross-device calls: Use RCP for remote invocation between devices or services.
  • Simple HTTP requests: Use Network Kit HTTP/HTTPS for easy integration and system-level performance optimization.
  • Complex HTTP requests: Use Axios for advanced features like interceptors and JSON auto-conversion, especially when code reuse across platforms is needed.

Written by Arif Emre Ankara

Leave a Reply