Skip to content

提供了丰富的可配置属性,能帮助开发人员在项目中便捷地进行请求管理。它简化了处理各类请求(如 HTTP 请求)的流程,并可依据应用的特定需求灵活定制请求行为。

License

Notifications You must be signed in to change notification settings

jokers-pub/front-requester

Repository files navigation

Joker Requester NPM Version

The @joker.front/requester library offers a wide range of configurable properties, which greatly assist developers in efficiently managing requests within their projects. It simplifies the process of handling various types of requests, such as HTTP requests, and provides flexibility in customizing the request behavior according to the specific requirements of the application.

How to Use

To start using the @joker.front/requester in your project, follow these steps:

import { Requester } from "@joker.front/requester";

// Create a new instance of the Requester class. The constructor accepts an object with configuration options.
// In this example, we set the 'base' option to '/server'. This base URL will be prepended to all the relative paths specified in the subsequent requests. It allows you to define a common root for your API endpoints, making it easier to manage and update the API URLs in case of any changes.
// You can also configure other options here, such as headers, timeouts, authentication mechanisms, etc., depending on your application's needs.
let requester = new Requester({
    base: "/server"
    //... other configuration options can be added here
});

// Use the'requester' instance to send a request. The'request' method takes two parameters: the first is the relative URL path of the request (in this case, "/user/add"), and the second is an object containing the request data.
// Here, we are sending a request to add a user. The request data includes the username and password. The data object can be used to send various types of data, such as form data, JSON data, etc., depending on the API's requirements.
requester.request("/user/add", {
    data: {
        userName: "zohar",
        pwd: "1234"
    }
});

Documentation

Official Website

Help Docs

Joker Requester

@joker.front/requester库提供了丰富的可配置属性,能帮助开发人员在项目中便捷地进行请求管理。它简化了处理各类请求(如 HTTP 请求)的流程,并可依据应用的特定需求灵活定制请求行为。

如何使用

在项目中开始使用@joker.front/requester,可按如下步骤操作:

import { Requester } from "@joker.front/requester";

// 创建Requester类的新实例。构造函数接受一个包含配置选项的对象。
// 在此示例中,我们将“base”选项设为“/server”。这个基础URL将被添加到后续请求中指定的所有相对路径之前。它能让您为API端点定义一个通用的根路径,以便在API URL发生变化时更易于管理和更新。
// 您还可以根据应用需求在此配置其他选项,如请求头、超时时间、认证机制等。
let requester = new Requester({
    base: "/server"
    //... 此处可添加其他配置选项
});

// 使用“requester”实例发送请求。“request”方法接受两个参数:第一个是请求的相对URL路径(在此例中为“/user/add”),第二个是包含请求数据的对象。
// 这里,我们正在发送一个添加用户的请求。请求数据包括用户名和密码。根据API要求,数据对象可用于发送各种类型的数据,如表单数据、JSON数据等。
requester.request("/user/add", {
    data: {
        userName: "zohar",
        pwd: "1234"
    }
});

文档

官网

帮助文档

About

提供了丰富的可配置属性,能帮助开发人员在项目中便捷地进行请求管理。它简化了处理各类请求(如 HTTP 请求)的流程,并可依据应用的特定需求灵活定制请求行为。

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published