Skip to content

Commit

Permalink
feat(core): add headers as a new argument of REST
Browse files Browse the repository at this point in the history
  • Loading branch information
Rani committed Jun 4, 2021
1 parent 23e60f6 commit b702b5b
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions app/scripts/modules/core/src/api/ApiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,17 @@ class DeprecatedRequestBuilderRoot extends DeprecatedRequestBuilder {

export const invalidContentMessage = 'API response was neither JSON nor zero-length html or text';

export function makeRequestBuilderConfig(pathPrefix?: string): IRequestBuilderConfig {
export function makeRequestBuilderConfig(
pathPrefix?: string,
headers?: IRequestBuilderConfig['headers'],
): IRequestBuilderConfig {
return {
url: joinPaths(pathPrefix),
cache: false,
data: undefined,
params: {},
timeout: (SETTINGS.pollSchedule || 30000) * 2 + 5000,
headers: { 'X-RateLimit-App': 'deck' },
headers: { 'X-RateLimit-App': 'deck', ...headers },
};
}

Expand All @@ -275,6 +278,6 @@ export const API: IDeprecatedRequestBuilder = new DeprecatedRequestBuilderRoot(m
* @param staticPathPrefix a static string, i.e., '/proxies/foo/endpoint' --
* avoid dynamic strings like `/entity/${id}`, use .path('entity', id) instead
*/
export const REST = (staticPathPrefix?: string): IRequestBuilder => {
return new RequestBuilder(makeRequestBuilderConfig(staticPathPrefix));
export const REST = (staticPathPrefix?: string, headers?: IRequestBuilderConfig['headers']): IRequestBuilder => {
return new RequestBuilder(makeRequestBuilderConfig(staticPathPrefix, headers));
};

0 comments on commit b702b5b

Please sign in to comment.