From 6b8baad94096225837dddc6ccf0826c59582d467 Mon Sep 17 00:00:00 2001 From: Gopal Jayaraman Date: Tue, 20 Apr 2021 18:14:06 +0530 Subject: [PATCH] fix(common): add body as an optional property on the options of HttpClient.delete (#19438) (#41723) adding optional body for HTTP delete request options. This new param added as an optional so won't break the existing code also provide the capability the send the body when and where it required. PR Close #41723 --- goldens/public-api/common/http/http.d.ts | 15 +++++++++++++++ packages/common/http/src/client.ts | 16 ++++++++++++++++ packages/common/http/test/client_spec.ts | 24 ++++++++++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/goldens/public-api/common/http/http.d.ts b/goldens/public-api/common/http/http.d.ts index e32d85bd3d..2eaea73e0a 100644 --- a/goldens/public-api/common/http/http.d.ts +++ b/goldens/public-api/common/http/http.d.ts @@ -18,6 +18,7 @@ export declare class HttpClient { reportProgress?: boolean; responseType: 'arraybuffer'; withCredentials?: boolean; + body?: any | null; }): Observable; delete(url: string, options: { headers?: HttpHeaders | { @@ -31,6 +32,7 @@ export declare class HttpClient { reportProgress?: boolean; responseType: 'blob'; withCredentials?: boolean; + body?: any | null; }): Observable; delete(url: string, options: { headers?: HttpHeaders | { @@ -44,6 +46,7 @@ export declare class HttpClient { reportProgress?: boolean; responseType: 'text'; withCredentials?: boolean; + body?: any | null; }): Observable; delete(url: string, options: { headers?: HttpHeaders | { @@ -57,6 +60,7 @@ export declare class HttpClient { reportProgress?: boolean; responseType: 'arraybuffer'; withCredentials?: boolean; + body?: any | null; }): Observable>; delete(url: string, options: { headers?: HttpHeaders | { @@ -70,6 +74,7 @@ export declare class HttpClient { reportProgress?: boolean; responseType: 'blob'; withCredentials?: boolean; + body?: any | null; }): Observable>; delete(url: string, options: { headers?: HttpHeaders | { @@ -83,6 +88,7 @@ export declare class HttpClient { reportProgress?: boolean; responseType: 'text'; withCredentials?: boolean; + body?: any | null; }): Observable>; delete(url: string, options: { headers?: HttpHeaders | { @@ -96,6 +102,7 @@ export declare class HttpClient { reportProgress?: boolean; responseType?: 'json'; withCredentials?: boolean; + body?: any | null; }): Observable>; delete(url: string, options: { headers?: HttpHeaders | { @@ -109,6 +116,7 @@ export declare class HttpClient { reportProgress?: boolean; responseType?: 'json'; withCredentials?: boolean; + body?: any | null; }): Observable>; delete(url: string, options: { headers?: HttpHeaders | { @@ -122,6 +130,7 @@ export declare class HttpClient { reportProgress?: boolean; responseType: 'arraybuffer'; withCredentials?: boolean; + body?: any | null; }): Observable>; delete(url: string, options: { headers?: HttpHeaders | { @@ -135,6 +144,7 @@ export declare class HttpClient { reportProgress?: boolean; responseType: 'blob'; withCredentials?: boolean; + body?: any | null; }): Observable>; delete(url: string, options: { headers?: HttpHeaders | { @@ -148,6 +158,7 @@ export declare class HttpClient { reportProgress?: boolean; responseType: 'text'; withCredentials?: boolean; + body?: any | null; }): Observable>; delete(url: string, options: { headers?: HttpHeaders | { @@ -161,6 +172,7 @@ export declare class HttpClient { reportProgress?: boolean; responseType?: 'json'; withCredentials?: boolean; + body?: any | null; }): Observable>; delete(url: string, options: { headers?: HttpHeaders | { @@ -174,6 +186,7 @@ export declare class HttpClient { reportProgress?: boolean; responseType?: 'json'; withCredentials?: boolean; + body?: any | null; }): Observable>; delete(url: string, options?: { headers?: HttpHeaders | { @@ -187,6 +200,7 @@ export declare class HttpClient { reportProgress?: boolean; responseType?: 'json'; withCredentials?: boolean; + body?: any | null; }): Observable; delete(url: string, options?: { headers?: HttpHeaders | { @@ -200,6 +214,7 @@ export declare class HttpClient { reportProgress?: boolean; responseType?: 'json'; withCredentials?: boolean; + body?: any | null; }): Observable; get(url: string, options: { headers?: HttpHeaders | { diff --git a/packages/common/http/src/client.ts b/packages/common/http/src/client.ts index 627610a272..b8041c0eca 100644 --- a/packages/common/http/src/client.ts +++ b/packages/common/http/src/client.ts @@ -619,6 +619,7 @@ export class HttpClient { {[param: string]: string | number | boolean | ReadonlyArray}, reportProgress?: boolean, responseType: 'arraybuffer', withCredentials?: boolean, + body?: any|null, }): Observable; @@ -639,6 +640,7 @@ export class HttpClient { {[param: string]: string | number | boolean | ReadonlyArray}, reportProgress?: boolean, responseType: 'blob', withCredentials?: boolean, + body?: any|null, }): Observable; /** @@ -658,6 +660,7 @@ export class HttpClient { {[param: string]: string | number | boolean | ReadonlyArray}, reportProgress?: boolean, responseType: 'text', withCredentials?: boolean, + body?: any|null, }): Observable; /** @@ -677,6 +680,7 @@ export class HttpClient { {[param: string]: string | number | boolean | ReadonlyArray}, reportProgress?: boolean, responseType: 'arraybuffer', withCredentials?: boolean, + body?: any|null }): Observable>; /** @@ -696,6 +700,7 @@ export class HttpClient { {[param: string]: string | number | boolean | ReadonlyArray}, reportProgress?: boolean, responseType: 'blob', withCredentials?: boolean, + body?: any|null, }): Observable>; /** @@ -715,6 +720,7 @@ export class HttpClient { {[param: string]: string | number | boolean | ReadonlyArray}, reportProgress?: boolean, responseType: 'text', withCredentials?: boolean, + body?: any|null, }): Observable>; /** @@ -735,6 +741,7 @@ export class HttpClient { reportProgress?: boolean, responseType?: 'json', withCredentials?: boolean, + body?: any|null, }): Observable>; /** @@ -755,6 +762,7 @@ export class HttpClient { reportProgress?: boolean, responseType?: 'json', withCredentials?: boolean, + body?: any|null, }): Observable>; /** @@ -773,6 +781,7 @@ export class HttpClient { {[param: string]: string | number | boolean | ReadonlyArray}, reportProgress?: boolean, responseType: 'arraybuffer', withCredentials?: boolean, + body?: any|null, }): Observable>; /** @@ -791,6 +800,7 @@ export class HttpClient { {[param: string]: string | number | boolean | ReadonlyArray}, reportProgress?: boolean, responseType: 'blob', withCredentials?: boolean, + body?: any|null, }): Observable>; /** @@ -809,6 +819,7 @@ export class HttpClient { {[param: string]: string | number | boolean | ReadonlyArray}, reportProgress?: boolean, responseType: 'text', withCredentials?: boolean, + body?: any|null, }): Observable>; /** @@ -829,6 +840,7 @@ export class HttpClient { reportProgress?: boolean, responseType?: 'json', withCredentials?: boolean, + body?: any|null, }): Observable>; /** @@ -848,6 +860,7 @@ export class HttpClient { reportProgress?: boolean, responseType?: 'json', withCredentials?: boolean, + body?: any|null, }): Observable>; /** @@ -868,6 +881,7 @@ export class HttpClient { reportProgress?: boolean, responseType?: 'json', withCredentials?: boolean, + body?: any|null, }): Observable; /** @@ -888,6 +902,7 @@ export class HttpClient { reportProgress?: boolean, responseType?: 'json', withCredentials?: boolean, + body?: any|null, }): Observable; /** @@ -908,6 +923,7 @@ export class HttpClient { reportProgress?: boolean, responseType?: 'arraybuffer'|'blob'|'json'|'text', withCredentials?: boolean, + body?: any|null, } = {}): Observable { return this.request('DELETE', url, options as any); } diff --git a/packages/common/http/test/client_spec.ts b/packages/common/http/test/client_spec.ts index a974b76b45..193c5f8233 100644 --- a/packages/common/http/test/client_spec.ts +++ b/packages/common/http/test/client_spec.ts @@ -177,6 +177,30 @@ import {toArray} from 'rxjs/operators'; testReq.flush('hello world'); }); }); + describe('makes a DELETE request', () => { + it('with body', done => { + const body = {data: 'json body'}; + client.delete('/test', {observe: 'response', responseType: 'text', body: body}) + .subscribe(res => { + expect(res.ok).toBeTruthy(); + expect(res.status).toBe(200); + done(); + }); + const testReq = backend.expectOne('/test'); + expect(testReq.request.body).toBe(body); + testReq.flush('hello world'); + }); + it('without body', done => { + client.delete('/test', {observe: 'response', responseType: 'text'}).subscribe(res => { + expect(res.ok).toBeTruthy(); + expect(res.status).toBe(200); + done(); + }); + const testReq = backend.expectOne('/test'); + expect(testReq.request.body).toBe(null); + testReq.flush('hello world'); + }); + }); describe('makes a JSONP request', () => { it('with properly set method and callback', done => { client.jsonp('/test', 'myCallback').subscribe(() => done());