Skip to content

Commit

Permalink
feat: add support for setting 'responseType' header for REST calls
Browse files Browse the repository at this point in the history
  • Loading branch information
shauke committed Apr 1, 2021
1 parent f8b2be6 commit e73343e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/app/core/services/api/api.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,20 @@ describe('Api Service', () => {
const req = httpTestingController.expectOne(`${REST_URL}/dummy`);
expect(req.request.headers.get(ApiService.AUTHORIZATION_HEADER_KEY)).toBeFalsy();
});

it('should have default response type of "json" if no other is provided', () => {
apiService.get('dummy').subscribe(fail, fail, fail);

const req = httpTestingController.expectOne(`${REST_URL}/dummy`);
expect(req.request.responseType).toEqual('json');
});

it('should append specific response type of "text" if provided', () => {
apiService.get('dummy', { responseType: 'text' }).subscribe(fail, fail, fail);

const req = httpTestingController.expectOne(`${REST_URL}/dummy`);
expect(req.request.responseType).toEqual('text');
});
});

describe('API Service exclusive runs', () => {
Expand Down
4 changes: 3 additions & 1 deletion src/app/core/services/api/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export function unpackEnvelope<T>(key: string = 'elements'): OperatorFunction<an
export interface AvailableOptions {
params?: HttpParams;
headers?: HttpHeaders;
responseType?: string;
skipApiErrorHandling?: boolean;
runExclusively?: boolean;
captcha?: Captcha;
Expand Down Expand Up @@ -151,8 +152,9 @@ export class ApiService {
defer(() =>
this.constructHeaders(options).pipe(
map(headers => ({
params: options?.params,
headers,
params: options?.params,
responseType: options?.responseType,
}))
)
),
Expand Down

0 comments on commit e73343e

Please sign in to comment.