创建 HTTP 服务

// import 


const httpService = new HttpService({ name: "demoService", deepDecoding: true });
const httpAction = httpService.createAction({
        // 名称;
        // 在同一个 HttpService 实例中具有唯一性;
        name: "myAction",

        // URL 路径;
        // 在同一个 HttpService 实例中具有唯一性;
        path: "/test/demo",

        //HTTP 方法; 有效值:"GET", "HEAD", "POST", "PUT", "DELETE", "CONNECT", "OPTIONS", "TRACE", "PATCH" ;
        method: "GET",
        headers: {
          "Content-Type": "application/json",
        },
        // 定义查询参数;
        queryParams:{
          p1:{
            // p1 参数:必须;
            required: false
          }
        }
    });

// 发起请求;
httpAction.request({
        params:{
          p1:"value1",
        }
      })
      .then((response) => {
        // 成功的回复: { success : true, code, status, message, data, redirectTo };
        LOGGER.debug("response... ", response);

      })
      .catch((error) => {
        // 失败的回复: { success : false, code, status, message };
        LOGGER.debug("error... ", error);
        //throw error;
      });


Last Updated:
Contributors: huanghaiquan
扫码咨询