@4lch4/axios-aid
Advanced tools
Comparing version 1.5.1 to 1.7.0
import { AxiosBasicCredentials } from 'axios'; | ||
/** | ||
* The only class exported by this module which contains the sole helper | ||
* function within the module. | ||
*/ | ||
export declare class AxiosAid { | ||
/** The instance of Axios used for executing requests. */ | ||
private client; | ||
/** Contains the headers that are used with the Axios instance. */ | ||
readonly headers?: RequestHeaders; | ||
/** | ||
* The constructor of the AxiosAid class. Accepts one mandatory base URL param | ||
* for whatever API/website you wish to interact with. Then when you use the | ||
* performRequest method, only provide the endpoint without the base and it | ||
* will be concatenated. If you supply a headers parameter, it will be used | ||
* as the request headers for every request sent. | ||
* | ||
* @param baseUrl The base URL for the API/website you wish to interact with. | ||
* @param headers An optional Object that can be passed as the headers of each request. | ||
* @param auth The optional credentials to provide if the API requires basic auth. | ||
*/ | ||
constructor(baseUrl: string, headers?: RequestHeaders, auth?: AxiosBasicCredentials); | ||
performRequest(method: RequestMethod, endpoint: string, payload?: RequestPayload, headers?: Object): Promise<import("axios").AxiosResponse<any>>; | ||
/** | ||
* Executes a request using the given HTTP method to the given endpoint. If a | ||
* payload is provided, it is either sent along in the request body or URL | ||
* parameters, depending on how it's provided. If any headers are provided, | ||
* they are sent along with this single request and not used for any future | ||
* requests. | ||
* | ||
* @param method The HTTP method you wish to perform/execute. | ||
* @param endpoint The endpoint of the API/website you wish to send a request to. | ||
* @param payload The optional request body or URL params of the request. | ||
* @param headers The optional headers to send along with the request. | ||
*/ | ||
performRequest(method: RequestMethod, endpoint: string, payload?: RequestPayload, headers?: Object): Promise<any>; | ||
} | ||
export interface RequestPayload { | ||
/** | ||
* The URL Parameters to be appended to the URL. Must be a POJO or | ||
* URLSearchParams object. | ||
*/ | ||
params?: Object; | ||
/** The data to be sent as the request body. */ | ||
data?: Object; | ||
@@ -15,4 +49,7 @@ } | ||
} | ||
/** | ||
* The available methods to be used/sent along with the request. | ||
*/ | ||
declare type RequestMethod = 'get' | 'GET' | 'delete' | 'DELETE' | 'head' | 'HEAD' | 'options' | 'OPTIONS' | 'post' | 'POST' | 'put' | 'PUT' | 'patch' | 'PATCH' | 'link' | 'LINK' | 'unlink' | 'UNLINK'; | ||
export default AxiosAid; | ||
export { AxiosBasicCredentials }; |
@@ -17,3 +17,18 @@ "use strict"; | ||
const axios_1 = __importDefault(require("axios")); | ||
/** | ||
* The only class exported by this module which contains the sole helper | ||
* function within the module. | ||
*/ | ||
class AxiosAid { | ||
/** | ||
* The constructor of the AxiosAid class. Accepts one mandatory base URL param | ||
* for whatever API/website you wish to interact with. Then when you use the | ||
* performRequest method, only provide the endpoint without the base and it | ||
* will be concatenated. If you supply a headers parameter, it will be used | ||
* as the request headers for every request sent. | ||
* | ||
* @param baseUrl The base URL for the API/website you wish to interact with. | ||
* @param headers An optional Object that can be passed as the headers of each request. | ||
* @param auth The optional credentials to provide if the API requires basic auth. | ||
*/ | ||
constructor(baseUrl, headers, auth) { | ||
@@ -28,2 +43,14 @@ this.client = axios_1.default.create({ | ||
} | ||
/** | ||
* Executes a request using the given HTTP method to the given endpoint. If a | ||
* payload is provided, it is either sent along in the request body or URL | ||
* parameters, depending on how it's provided. If any headers are provided, | ||
* they are sent along with this single request and not used for any future | ||
* requests. | ||
* | ||
* @param method The HTTP method you wish to perform/execute. | ||
* @param endpoint The endpoint of the API/website you wish to send a request to. | ||
* @param payload The optional request body or URL params of the request. | ||
* @param headers The optional headers to send along with the request. | ||
*/ | ||
performRequest(method, endpoint, payload, headers) { | ||
@@ -30,0 +57,0 @@ return __awaiter(this, void 0, void 0, function* () { |
{ | ||
"name": "@4lch4/axios-aid", | ||
"displayName": "AxiosAid", | ||
"version": "1.5.1", | ||
"version": "1.7.0", | ||
"description": "A lightweight wrapper around Axios for type data and ease of use.", | ||
@@ -6,0 +6,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7546
121