Skip to content

Commit 26ee5c9

Browse files
fix(common): add body as an optional property on the options of HttpClient.delete (#19438)
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.
1 parent 251bec1 commit 26ee5c9

3 files changed

Lines changed: 55 additions & 0 deletions

File tree

goldens/public-api/common/http/http.d.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export declare class HttpClient {
1818
reportProgress?: boolean;
1919
responseType: 'arraybuffer';
2020
withCredentials?: boolean;
21+
body?: any | null;
2122
}): Observable<ArrayBuffer>;
2223
delete(url: string, options: {
2324
headers?: HttpHeaders | {
@@ -31,6 +32,7 @@ export declare class HttpClient {
3132
reportProgress?: boolean;
3233
responseType: 'blob';
3334
withCredentials?: boolean;
35+
body?: any | null;
3436
}): Observable<Blob>;
3537
delete(url: string, options: {
3638
headers?: HttpHeaders | {
@@ -44,6 +46,7 @@ export declare class HttpClient {
4446
reportProgress?: boolean;
4547
responseType: 'text';
4648
withCredentials?: boolean;
49+
body?: any | null;
4750
}): Observable<string>;
4851
delete(url: string, options: {
4952
headers?: HttpHeaders | {
@@ -57,6 +60,7 @@ export declare class HttpClient {
5760
reportProgress?: boolean;
5861
responseType: 'arraybuffer';
5962
withCredentials?: boolean;
63+
body?: any | null;
6064
}): Observable<HttpEvent<ArrayBuffer>>;
6165
delete(url: string, options: {
6266
headers?: HttpHeaders | {
@@ -70,6 +74,7 @@ export declare class HttpClient {
7074
reportProgress?: boolean;
7175
responseType: 'blob';
7276
withCredentials?: boolean;
77+
body?: any | null;
7378
}): Observable<HttpEvent<Blob>>;
7479
delete(url: string, options: {
7580
headers?: HttpHeaders | {
@@ -83,6 +88,7 @@ export declare class HttpClient {
8388
reportProgress?: boolean;
8489
responseType: 'text';
8590
withCredentials?: boolean;
91+
body?: any | null;
8692
}): Observable<HttpEvent<string>>;
8793
delete(url: string, options: {
8894
headers?: HttpHeaders | {
@@ -96,6 +102,7 @@ export declare class HttpClient {
96102
reportProgress?: boolean;
97103
responseType?: 'json';
98104
withCredentials?: boolean;
105+
body?: any | null;
99106
}): Observable<HttpEvent<Object>>;
100107
delete<T>(url: string, options: {
101108
headers?: HttpHeaders | {
@@ -109,6 +116,7 @@ export declare class HttpClient {
109116
reportProgress?: boolean;
110117
responseType?: 'json';
111118
withCredentials?: boolean;
119+
body?: any | null;
112120
}): Observable<HttpEvent<T>>;
113121
delete(url: string, options: {
114122
headers?: HttpHeaders | {
@@ -122,6 +130,7 @@ export declare class HttpClient {
122130
reportProgress?: boolean;
123131
responseType: 'arraybuffer';
124132
withCredentials?: boolean;
133+
body?: any | null;
125134
}): Observable<HttpResponse<ArrayBuffer>>;
126135
delete(url: string, options: {
127136
headers?: HttpHeaders | {
@@ -135,6 +144,7 @@ export declare class HttpClient {
135144
reportProgress?: boolean;
136145
responseType: 'blob';
137146
withCredentials?: boolean;
147+
body?: any | null;
138148
}): Observable<HttpResponse<Blob>>;
139149
delete(url: string, options: {
140150
headers?: HttpHeaders | {
@@ -148,6 +158,7 @@ export declare class HttpClient {
148158
reportProgress?: boolean;
149159
responseType: 'text';
150160
withCredentials?: boolean;
161+
body?: any | null;
151162
}): Observable<HttpResponse<string>>;
152163
delete(url: string, options: {
153164
headers?: HttpHeaders | {
@@ -161,6 +172,7 @@ export declare class HttpClient {
161172
reportProgress?: boolean;
162173
responseType?: 'json';
163174
withCredentials?: boolean;
175+
body?: any | null;
164176
}): Observable<HttpResponse<Object>>;
165177
delete<T>(url: string, options: {
166178
headers?: HttpHeaders | {
@@ -174,6 +186,7 @@ export declare class HttpClient {
174186
reportProgress?: boolean;
175187
responseType?: 'json';
176188
withCredentials?: boolean;
189+
body?: any | null;
177190
}): Observable<HttpResponse<T>>;
178191
delete(url: string, options?: {
179192
headers?: HttpHeaders | {
@@ -187,6 +200,7 @@ export declare class HttpClient {
187200
reportProgress?: boolean;
188201
responseType?: 'json';
189202
withCredentials?: boolean;
203+
body?: any | null;
190204
}): Observable<Object>;
191205
delete<T>(url: string, options?: {
192206
headers?: HttpHeaders | {
@@ -200,6 +214,7 @@ export declare class HttpClient {
200214
reportProgress?: boolean;
201215
responseType?: 'json';
202216
withCredentials?: boolean;
217+
body?: any | null;
203218
}): Observable<T>;
204219
get(url: string, options: {
205220
headers?: HttpHeaders | {

packages/common/http/src/client.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,7 @@ export class HttpClient {
619619
{[param: string]: string | number | boolean | ReadonlyArray<string|number|boolean>},
620620
reportProgress?: boolean, responseType: 'arraybuffer',
621621
withCredentials?: boolean,
622+
body?: any|null,
622623
}): Observable<ArrayBuffer>;
623624

624625

@@ -639,6 +640,7 @@ export class HttpClient {
639640
{[param: string]: string | number | boolean | ReadonlyArray<string|number|boolean>},
640641
reportProgress?: boolean, responseType: 'blob',
641642
withCredentials?: boolean,
643+
body?: any|null,
642644
}): Observable<Blob>;
643645

644646
/**
@@ -658,6 +660,7 @@ export class HttpClient {
658660
{[param: string]: string | number | boolean | ReadonlyArray<string|number|boolean>},
659661
reportProgress?: boolean, responseType: 'text',
660662
withCredentials?: boolean,
663+
body?: any|null,
661664
}): Observable<string>;
662665

663666
/**
@@ -677,6 +680,7 @@ export class HttpClient {
677680
{[param: string]: string | number | boolean | ReadonlyArray<string|number|boolean>},
678681
reportProgress?: boolean, responseType: 'arraybuffer',
679682
withCredentials?: boolean,
683+
body?: any|null
680684
}): Observable<HttpEvent<ArrayBuffer>>;
681685

682686
/**
@@ -696,6 +700,7 @@ export class HttpClient {
696700
{[param: string]: string | number | boolean | ReadonlyArray<string|number|boolean>},
697701
reportProgress?: boolean, responseType: 'blob',
698702
withCredentials?: boolean,
703+
body?: any|null,
699704
}): Observable<HttpEvent<Blob>>;
700705

701706
/**
@@ -715,6 +720,7 @@ export class HttpClient {
715720
{[param: string]: string | number | boolean | ReadonlyArray<string|number|boolean>},
716721
reportProgress?: boolean, responseType: 'text',
717722
withCredentials?: boolean,
723+
body?: any|null,
718724
}): Observable<HttpEvent<string>>;
719725

720726
/**
@@ -735,6 +741,7 @@ export class HttpClient {
735741
reportProgress?: boolean,
736742
responseType?: 'json',
737743
withCredentials?: boolean,
744+
body?: any|null,
738745
}): Observable<HttpEvent<Object>>;
739746

740747
/**
@@ -755,6 +762,7 @@ export class HttpClient {
755762
reportProgress?: boolean,
756763
responseType?: 'json',
757764
withCredentials?: boolean,
765+
body?: any|null,
758766
}): Observable<HttpEvent<T>>;
759767

760768
/**
@@ -773,6 +781,7 @@ export class HttpClient {
773781
{[param: string]: string | number | boolean | ReadonlyArray<string|number|boolean>},
774782
reportProgress?: boolean, responseType: 'arraybuffer',
775783
withCredentials?: boolean,
784+
body?: any|null,
776785
}): Observable<HttpResponse<ArrayBuffer>>;
777786

778787
/**
@@ -791,6 +800,7 @@ export class HttpClient {
791800
{[param: string]: string | number | boolean | ReadonlyArray<string|number|boolean>},
792801
reportProgress?: boolean, responseType: 'blob',
793802
withCredentials?: boolean,
803+
body?: any|null,
794804
}): Observable<HttpResponse<Blob>>;
795805

796806
/**
@@ -809,6 +819,7 @@ export class HttpClient {
809819
{[param: string]: string | number | boolean | ReadonlyArray<string|number|boolean>},
810820
reportProgress?: boolean, responseType: 'text',
811821
withCredentials?: boolean,
822+
body?: any|null,
812823
}): Observable<HttpResponse<string>>;
813824

814825
/**
@@ -829,6 +840,7 @@ export class HttpClient {
829840
reportProgress?: boolean,
830841
responseType?: 'json',
831842
withCredentials?: boolean,
843+
body?: any|null,
832844
}): Observable<HttpResponse<Object>>;
833845

834846
/**
@@ -848,6 +860,7 @@ export class HttpClient {
848860
reportProgress?: boolean,
849861
responseType?: 'json',
850862
withCredentials?: boolean,
863+
body?: any|null,
851864
}): Observable<HttpResponse<T>>;
852865

853866
/**
@@ -868,6 +881,7 @@ export class HttpClient {
868881
reportProgress?: boolean,
869882
responseType?: 'json',
870883
withCredentials?: boolean,
884+
body?: any|null,
871885
}): Observable<Object>;
872886

873887
/**
@@ -888,6 +902,7 @@ export class HttpClient {
888902
reportProgress?: boolean,
889903
responseType?: 'json',
890904
withCredentials?: boolean,
905+
body?: any|null,
891906
}): Observable<T>;
892907

893908
/**
@@ -908,6 +923,7 @@ export class HttpClient {
908923
reportProgress?: boolean,
909924
responseType?: 'arraybuffer'|'blob'|'json'|'text',
910925
withCredentials?: boolean,
926+
body?: any|null,
911927
} = {}): Observable<any> {
912928
return this.request<any>('DELETE', url, options as any);
913929
}

packages/common/http/test/client_spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,30 @@ import {toArray} from 'rxjs/operators';
177177
testReq.flush('hello world');
178178
});
179179
});
180+
describe('makes a DELETE request', () => {
181+
it('with body', done => {
182+
const body = {data: 'json body'};
183+
client.delete('/test', {observe: 'response', responseType: 'text', body: body})
184+
.subscribe(res => {
185+
expect(res.ok).toBeTruthy();
186+
expect(res.status).toBe(200);
187+
done();
188+
});
189+
const testReq = backend.expectOne('/test');
190+
expect(testReq.request.body).toBe(body);
191+
testReq.flush('hello world');
192+
});
193+
it('without body', done => {
194+
client.delete('/test', {observe: 'response', responseType: 'text'}).subscribe(res => {
195+
expect(res.ok).toBeTruthy();
196+
expect(res.status).toBe(200);
197+
done();
198+
});
199+
const testReq = backend.expectOne('/test');
200+
expect(testReq.request.body).toBe(null);
201+
testReq.flush('hello world');
202+
});
203+
});
180204
describe('makes a JSONP request', () => {
181205
it('with properly set method and callback', done => {
182206
client.jsonp('/test', 'myCallback').subscribe(() => done());

0 commit comments

Comments
 (0)