Plugin API
English
English
  • Getting Started
    • Introduction
    • Your First Plugin
    • File Structure Overview
    • Plugin Types
      • Window
      • Background Service
      • Format Extension
      • Inspector
    • Debug Plugin
  • Distribution
    • Prepare Plugin
    • Package Plugin
    • Publish Plugin
    • Update Plugin
    • Developer Policies
    • Plugin Icon Template
  • Developer Guide
    • manifest.json Configuration
    • Retrieve Data
    • Modify Data
    • Access Local Files
    • Issue Network Requests
    • Using Node.js Native API
    • Using Third-Party Modules
    • Multilingual (i18n)
    • Frameless Window
  • API Reference
    • event
    • item
    • folder
    • tag
    • tagGroup
    • library
    • window
    • app
    • os
    • screen
    • notification
    • contextMenu
    • dialog
    • clipboard
    • drag
    • shell
    • log
  • Extra Moudle
    • FFmpeg
Powered by GitBook
On this page
  • Using fetch to Make Network Requests
  • Using https to Make Requests
  1. Developer Guide

Issue Network Requests

You can use the fetch method provided by web technologies or the native https module in Node.js to make network requests.

PreviousAccess Local FilesNextUsing Node.js Native API

Last updated 2 years ago

Using fetch to Make Network Requests

The fetch function is a tool for accessing network resources, allowing you to send HTTP requests and handle response processing. The fetch function supports many different types of requests, including GET, POST, PUT, and DELETE, and supports custom formats for request and response bodies.

By using the fetch function, you can easily access network resources and control the request and response process. For example, you can use the following code to send a GET request and process the response after the request is fulfilled:

fetch('https://example.com/api/endpoint')
    .then(response => response.json())
    .then(data => {
    	// Process the response here
    });

This example code sends a GET request to the specified network resource, then parses the response body into JSON format after the request is completed, and processes the parsed response body here.

To learn more about the fetch function in Javascript, it is recommended to read the introduction on the MDN website: .

This article introduces the basic usage of the fetch function and provides example code demonstrating how to use fetch to send HTTP requests and handle response processing.

In addition, you can refer to the following articles for more information about fetch:

  • "Using Fetch" ()

  • "Fetch API In Depth" ()


Using https to Make Requests

Due to the default security limitations of browsers, the fetch method sometimes encounters some restrictions. In this case, we can switch to using Node.js native networking APIs to send network requests for greater flexibility.

Sending an HTTP GET request using the https.get method is very simple; you only need to provide the URL of the request. For example, you can use the following code to send an HTTP GET request:

const https = require('https');

https.get('https://www.example.com', (res) => {
  console.log(`Got response: ${res.statusCode}`);

  res.on('data', (d) => {
    // Process response data
  });

}).on('error', (e) => {
  console.error(`Got error: ${e.message}`);
});
https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
https://davidwalsh.name/fetch
https://css-tricks.com/using-fetch/