Skip to content

Commit

Permalink
Merge pull request #18 from lemoncloud-io/feature/louis-add-http-buil…
Browse files Browse the repository at this point in the history
…der2

feat: add HttpRequestBuilder without credentials
  • Loading branch information
louis-lemon authored Jun 6, 2024
2 parents ea56783 + 295861d commit 42bd820
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 2 deletions.
42 changes: 41 additions & 1 deletion src/core/aws-web.core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AWSWebCoreState, Body, LemonCredentials, LemonKMS, LemonOAuthToken, Par
import { AWSStorageService, USE_X_LEMON_IDENTITY_KEY } from '../token-storage';
import { calcSignature, LoggerService } from '../utils';
import { AxiosRequestConfig, AxiosResponse } from 'axios';
import { AWSHttpRequestBuilder } from '../http';
import { AWSHttpRequestBuilder, HttpRequestBuilder } from '../http';
import AWS from 'aws-sdk/global.js';

/**
Expand Down Expand Up @@ -62,6 +62,46 @@ export class AWSWebCore implements WebCoreService {
return 'build';
}

/**
* Builds a request using HttpRequestBuilder without Credentials.
* @param {AxiosRequestConfig} config - The Axios request configuration.
* @returns {HttpRequestBuilder} - The HttpRequestBuilder instance.
*/
buildRequest(config: AxiosRequestConfig): HttpRequestBuilder {
return new HttpRequestBuilder(config);
}

/**
* Executes a HTTP request without Credentials.
* @template T
* @param {string} method - The HTTP method.
* @param {string} url - The request URL.
* @param {Params} [params={}] - The request parameters.
* @param {Body} body - The request body.
* @param {AxiosRequestConfig} [config] - Additional Axios request configuration.
* @returns {Promise<AxiosResponse<T>>} - The Axios response.
*/
async request<T>(
method: string,
url: string,
params: Params = {},
body?: Body,
config?: AxiosRequestConfig
): Promise<AxiosResponse<T>> {
const builder = new HttpRequestBuilder({
method,
baseURL: url,
params,
});
if (body) {
builder.setBody(body);
}
if (config) {
builder.addAxiosRequestConfig(config);
}
return await builder.execute();
}

/**
* Builds a signed request using AWSHttpRequestBuilder.
* @param {AxiosRequestConfig} config - The Axios request configuration.
Expand Down
42 changes: 41 additions & 1 deletion src/core/azure-web.core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AzureWebCoreState, Body, LemonOAuthToken, Params, WebCoreConfig, WebCor
import { AzureStorageService, USE_X_LEMON_IDENTITY_KEY } from '../token-storage';
import { LoggerService } from '../utils';
import { AxiosRequestConfig, AxiosResponse } from 'axios';
import { AzureHttpRequestBuilder } from '../http';
import { AzureHttpRequestBuilder, HttpRequestBuilder } from '../http';

/**
* Class to handle Azure-specific web core operations.
Expand Down Expand Up @@ -42,6 +42,46 @@ export class AzureWebCore implements WebCoreService {
return 'has-token';
}

/**
* Builds a request using HttpRequestBuilder without Credentials.
* @param {AxiosRequestConfig} config - The Axios request configuration.
* @returns {HttpRequestBuilder} - The HttpRequestBuilder instance.
*/
buildRequest(config: AxiosRequestConfig): HttpRequestBuilder {
return new HttpRequestBuilder(config);
}

/**
* Executes a HTTP request without Credentials.
* @template T
* @param {string} method - The HTTP method.
* @param {string} url - The request URL.
* @param {Params} [params={}] - The request parameters.
* @param {Body} body - The request body.
* @param {AxiosRequestConfig} [config] - Additional Axios request configuration.
* @returns {Promise<AxiosResponse<T>>} - The Axios response.
*/
async request<T>(
method: string,
url: string,
params: Params = {},
body?: Body,
config?: AxiosRequestConfig
): Promise<AxiosResponse<T>> {
const builder = new HttpRequestBuilder({
method,
baseURL: url,
params,
});
if (body) {
builder.setBody(body);
}
if (config) {
builder.addAxiosRequestConfig(config);
}
return await builder.execute();
}

/**
* Builds a signed request using the provided Axios configuration.
* @param {AxiosRequestConfig} config - The Axios request configuration.
Expand Down

0 comments on commit 42bd820

Please sign in to comment.