创建axios的示例

2wnc66cl  于 2021-09-23  发布在  Java
关注(0)|答案(0)|浏览(159)

如何从函数中共享接口
也许更好的方法是创建axios示例并在这里和其他功能中使用它?
如果每个函数中没有方法和头等属性,代码是否会更干净?

const axios = require("axios");
interface AddressCheckResult {
  pickupLocation: {
    locationId: number;
    name: string;
      coordinates: {
        longitude: string;
        latitude: string;
      };
    };
  };
  deliveryAddress: {
    postcode: string;
    houseNumber: number;
  };
}
interface AddressCheckPayload {
  pickupAddress: {
    postcode: string;
    houseNumber: string;
  };
  deliveryAddress: {
    postcode: string;
  };
}
export const addressCheck = async (
  apiKey: string,
  payload: AddressCheckPayload,
  apiBaseUrl: string
): Promise<AddressCheckResult> => {
  let response = await axios({
    method: "post",
    url: `${apiBaseUrl}address-check`,
    data: payload,
    headers: {
      Authorization: `Bearer ${apiKey}`,
    },
  });
  return response.data as AddressCheckResult;
};

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题